def main():
distance, fuel = 0.0, 0.0
inStr = input ("Enter gallons and miles (with a space between):")
while inStr != "":
gallons,miles = inStr.split()
gallons = eval(gallons)
miles = eval(miles)
print("MPG for this leg: {0:0.1f}".format(miles/gallons))
distance = distance + miles
fuel = fuel + gallons
inStr = input("Enter gallons and miles (with a space between): ")
#???the program knows there are no more legs in the journey when the user enters no input for a leg. How do I write the code for this?
print()
print("You traveled a total of {0:0.1f} miles on {1:0.1f} gallons."
.format(distance,fuel))
print ("The fuel efficiency was {0:0.1f} miles per gallon."
.format(distance/fuel))
if __name__ == '__main__':
main()
just_starting 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.