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!!

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.