[Tutor] User input

Kelly Vincent kpvincent at yahoo.com
Mon May 22 16:19:12 CEST 2006


raw_input reads in the value as a string, so you need
to convert it at some point to a number. You can
either do this at the point where you read the value
in, or when you do the calculation/print. 

To convert it at the input stage (probably the most
logical), add float() such as
mpg = float(raw_input (" Enter your mileage:"))
instead of
mpg = raw_input (" Enter your mileage:")

Or you can do it in the print statement:
print "Total trip cost is US$", float(distance) /
(float(mpg) * float(galon_price))

HTH



--- MATATA EMMANUEL <emmatata at hotmail.com> wrote:

---------------------------------

Hi there,

Can anyone tell me how I'm having trouble executing
this piece of code: 

mpg = raw_input (" Enter your mileage:")
distance = raw_input ("Enter your distance:")
galon_price = raw_input ("Enter you cost per gallon:")
make = "Honda"
model = "Accord"
##
print make, model, "mileage is", mpg, "miles per
gallon"
print "Total trip cost is US$", distance / (mpg *
gallon_price)


I get this error when I run it:

print "Total trip cost is US$", distance / (mpg *
gallon_price)
TypeError: unsupported operand type(s) for *




Matt

> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list