[Tutor] Re: Newbie - mixing floats and integers
missive at hotmail.com
Sun Apr 11 19:22:32 EDT 2004
>arg1 = raw_input("What is your first number?:")
>oper = raw_input("What operation: +, -, *, / ?")
>arg3 = raw_input("What is your second number?:")
>num1 = long(arg1)
>#oper = arg 
>num2 = long(arg3)
>if oper == "+":
> answer = num1+num2
>elif oper == "-":
> answer = num1-num2
>elif oper == "/":
> answer = (num1/num2)
>elif oper == "x":
> answer = (num1*num2)
>print num1, oper, num2, "=", answer
>However, when I try and run this program with floats, it won't work and
>I get errors. Is there something I have to do to enable this to work
>with both floats and integers?
What input? What errors?
Most likely, what you want to do is use float(arg) instead of long(arg)
long() is going to produce a long integer, which in python is an
integer that can be arbitrarily large (or anti-large).
Remember that you can run some of this stuff by the interactive
interpreter to see what it means ...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for float(): thirty-five
The new MSN 8: advanced junk mail protection and 2 months FREE*
More information about the Tutor