On Thu, Sep 18, 2008 at 5:14 AM, <[EMAIL PROTECTED]> wrote: > When <variable> = raw_input ( " please enter a number " ) > <variable> = int (<variable>) is run as part of a python script It should > take in the user stored input and store it as an integer. Am I correct. The > string represented by <variable> in memory is now represented by 5 for > example? > If this is correct why do I get an error regarding the division of two > strings if i type print " < variable> " / < variable>
well if you have something like this: miles = int("5") gallons = 1 print "miles"/gallon the " " around miles turns miles into a string. And you just can't do that. Here's a proper example of an mpg calculator: def mpg(): miles = int( raw_input("Miles driven: ")) gallons = int( raw_input("Gallons used: ")) print "Your Miles Per Gallon: ", miles/gallons although converting them to float would allow you a little more accuracy in your measurements. But if you're just looking at whole number values, that should be fine. HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor