small medium large xlarge

Hi,

I just wanted to check to see if I did this right. My answer seems OK… it’s not exactly the same as what the book says I should get. I seem to get 7.78 for (100,30) and 11.67 for (150,30. Any suggestions/comments are appreciated… thanks! Here is my code:

7 #Exercise #7 8 9 def convert_mileage(mpg): 10 liter_per_gallon = 3.7 11 kilometer_per_mile = 1.6 12 return (100 * liter_per_gallon) / (kilometer_per_mile * mpg) 13 14 #print convert_mileage(20) 15 16 #Exercise 9 17 18 def liters_needed(distance, gas): 19 distance = distance * 0.6 20 gas = convert_mileage(gas) 21 return distance/gas 22 23 print liters_needed(150,30)

It looks like your code has the right structure; you are getting a different answer than expected because your conversions don’t use the same number of significant digits as we did in our version.

def convert_mileage(mileage): kmperliter=mileage1.6093443.78541178 return (1/(kmperliter*100)) SyntaxError: invalid syntax

What’s wrong with the syntax ?

Hi Stephan,

You need to use the multiplication operator in your assignment statement:

``````kmperliter = mileage * 1.609344 * 3.78541178
``````