0

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 by ~s.o.s~: Added code tags, please learn to use them.

2
Contributors
4
Replies
14
Views
5 Years
Discussion Span
Last Post by graphicsgrl
0

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

Edited by happygeek: fixed formatting

0

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 by happygeek: fixed formatting

0

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 by pyTony: n/a

0

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 by graphicsgrl: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.