[Tutor] User input
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Mon May 22 17:28:33 CEST 2006
> The second version works.
>
> print "Total trip cost is US$", float(distance) /
> (float(mpg) * float(galon_price))
Hi Matt,
Although this works, we'll probably want to do the type conversions as
early as possible. We can write a function input_float() that wraps up
the float(raw_input()) stuff:
###################################
def input_float(prompt):
return float(raw_input(prompt))
###################################
If we have this as a helper function, then we don't have to worry about
sprinkling float() conversions all over the place.
More information about the Tutor
mailing list