21 Jul 2011, 23:35
Generic-user-small

Giovanni Flores (1 post)

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)

25 Jul 2011, 21:41
Paul_mugshot_pragsmall

Paul Gries (44 posts)

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.

27 Dec 2011, 11:01
Oppa1_pragsmall

Stephan Goldenberg (14 posts)

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

What’s wrong with the syntax ?

02 Jan 2012, 16:41
Paul_mugshot_pragsmall

Paul Gries (44 posts)

Hi Stephan,

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

kmperliter = mileage * 1.609344 * 3.78541178

Is that what you’re asking?

24 Jun 2012, 18:14
Generic-user-small

Ivan Winters (3 posts)

BTW Your book is published in the US and uses US gallons for this question. I live in the UK and use UK gallons. Conversion factor UK gallons to litre is 4.54 approx

  You must be logged in to comment