do you guys help newbies??

Duncan Booth duncan at rcp.co.uk
Wed Nov 27 09:20:00 EST 2002


malik m <malik_martin at hotmail.com> wrote in news:r2c9uusgkvesmqout846rdge47bg5tui6d at 4ax.com:

> hi yea i messed up here's the code sorry about the html too i was
> using it through hotmail while i learnd and still am learning how to
> use newsgroups....

You still need to figure out how to stop your posting word-wrapping when
you post long lines of Python. Mind you, so do most of us.

> 
> #chapter 3 test control structures 3.3
> print "hello, this program will tell me how many miles per gallon your
> car drives by the \n amount of miles entered by the user along with
> the size of his/her tank."
You could write this more clearly using a triple quoted string:

print '''hello, this program will tell me how many miles per gallon
your car drives by the amount of miles entered by the user along with
the size of his/her tank.'''

> 
> #initialize variables
> totalMilesDriven = 0 #total miles driven
> 
> totalGallonsPerTank = 0 #total gallons per tank
> 
> counter = 0 #bogus counter
> 
> #processing phase
> gallonsPerTank = raw_input("Enter how many gallons your tank holds, -1
> to end:")
> gallonsPerTank = int(gallonsPerTank)
> 
> milesDriven = raw_input("enter how many miles driven, -1 to end:")
> milesDriven = int(milesDriven)
> 
> while gallonsPerTank or milesDriven != -1:

I think you meant:
   while gallonsPerTank != -1 or milesDriven != -1:

>     averagea = milesDriven / gallonsPerTank
>     counter = counter + 1
>     print "your miles per gallon are", averagea
>     totalMilesDriven = totalMilesDriven + milesDriven
>     totalGallonsPerTank = totalGallonsPerTank + gallonsPerTank
>     gallonsPerTank = raw_input("Enter how many gallons your tank
> holds, -1 to end:")
>     milesDriven = raw_input("enter how many miles driven, -1 to end:")

You forgot to convert the input to integers this time round.
> 
> #termination phase
> if counter != 0:
>     average = float( totalMilesDriven ) / float( totalGallonsPerTank )
>     print "The total miles per gallon is", average
> else:
>     print "No data entered"
> 




More information about the Python-list mailing list