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()

You hit the Enter key without any data. You should know what the code does even if you get it from someone else. What is necessary to exit in this code?

in_str=""
    while in_str != "q":

You hit the Enter key without any data. You should know what the code does even if you get it from someone else. What is necessary to exit in this code?

in_str=""
    while in_str != "q":

Thanks!!

This question has already been answered. Start a new discussion instead.