I am new to python(version 3.2.11) and having some problems with this code...Please Help!!
Here is the program I am supposed to write: Write a program which computes the fuel efficiency of a multi-leg journey. The program will prompt the user for the starting odometer reading and then for information about each leg in the journey. For each leg, prompt the user for the current odometer reading and the amount of gas they used. The program knows there are no more legs in the journey when the user enters no input for a leg. The program is to print out the miles per gallon achieved on each leg of the journey and the total miles per gallon for the trip.

def main():
    stmi = input("Please enter the starting odometer reading: ")
    tgas = 0.0
    if stmi != "":
        legmi, gas = input("Please enter the leg miles and the gas (leg miles,gas) or press enter for total miles per gallon: ")
        if legmi != "":
            dist = legmi - stmi
            lmpg = dist/gas
            while legmi != "":
                tgas = tgas + gas
                print ("The miles per gallon of the leg is ", lmpg)
                stmi = legmi
                legmi, gas = input("Please enter the leg miles and the gas (leg miles,gas) or press enter for total miles per gallon: ")
        else:
            tmpg = (legmi - stmi)/tgas
            print ("The total miles per gallon is ", tmpg)

main()

Edited 5 Years Ago by ~s.o.s~: Added code tags, please learn to use them.

You must use a while loop and post the corrected code with CODE tags.

Edited 3 Years Ago by happygeek: fixed formatting

You must use a while loop and post the corrected code with CODE tags.

Thank you!! But,I am still not getting it...the while is in the code.

Edited 3 Years Ago by happygeek: fixed formatting

I could not read it as tags were missing and i only browsed it quickly. Pleae post with tags and study this : http://en.m.wikipedia.org/wiki/Don't_repeat_yourself

legmi, gas = input("Please enter the leg miles and the gas (leg miles,gas) or press enter for total miles per gallon: ")

By the way waits two character input and puts first to legmi and second to gas (if you use Python3 like your print statements would suggest).

Edited 5 Years Ago by pyTony: n/a

I could not read it as tags were missing and i only browsed it quickly. Pleae post with tags and study this : http://en.m.wikipedia.org/wiki/Don't_repeat_yourself

legmi, gas = input("Please enter the leg miles and the gas (leg miles,gas) or press enter for total miles per gallon: ")

By the way waits two character input and puts first to legmi and second to gas (if you use Python3 like your print statements would suggest).

Thanks!!

Edited 5 Years Ago by graphicsgrl: n/a

This article has been dead for over six months. Start a new discussion instead.