I am currently taking a college intro to programming course but the professor blatantly sucks at explaining concepts, so I was hoping I could get some help from the programmers of this board!
I have to write a program that gets the miles per gallon for 5 legs of a trip inputted by the user. I can easily get one leg.. but how do i get the other 4? I have to use a while loop but have no idea how to implement it into such a program. how do i connect these?
** I really want to understand the concepts behind this so if someone could point me in the right direction or explain thoroughly as opposed to just doing it for me I would be greatly appreciative.
this is what I have thus far.
leg = 0
legCounter = 5
while leg <= legCounter:
leg = leg + 1
#the user input amount of miles driven by user
milesDriven = int(input('how many miles have you driven?'))
#the amount of gallons the user has input
gallonsUsed = int(input('how many gallons have you used?'))
# the miles per gallon
milesPerGallon = int(milesDriven / gallonsUsed)
# display the miles per gallon
print ('your miles per gallon are')
print (str(milesPerGallon))
input()


Sign In
Create Account

Back to top









