[Tutor] Need Assistants with Python Please

Alan Gauld alan.gauld at btinternet.com
Sun Mar 15 16:42:38 CET 2009


"Jared White" <dukelx2005 at gmail.com> wrote

> So far ive come up with this code.  But it seems not to be working, 
> Can
> someone please help me figure out what ive done wrong
>
> def main ():
>    print "The program converts Miles Per Gallon (US) to Liters Per 
> 100
> Kilometer."
>    kilometers = input ("What is the Miles Per Gallon?")

This might be better named mpg?

>    MilesperUSGallon * (1.60934/3.78541) = kilometersperliter. 
> 1/(kilometers
> per liter) = liters per kilometer. Liters/kilometer * 100 = liters 
> per 100
> km.

I have no idea what you think this line does but it isn't valid Python
so you will get an error!

MilesperUSGallon * (1.60934/3.78541) = kilometersperliter

This bit is almost valid except you dont define kilometersperliter
anywhere.

. 1/(kilometers per liter) = liters per kilometer. Liters/kilometer * 
100 = liters per 100 km.

But this makes no sense whatsoever to me or Python...

Do you think the dot at the front makes it a comment maybe?
If so you need to use a # sign. But I'm still notclear what
the comment refers to in your program?

>    print "The Distance in Miles per Gallon", miles\

And I'm not sure why there is a \ at the end of this line?

> But is has giving me an error like ive done something wrong with the
> spacing..

HTH,


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list