[Tutor] Newbie - mixing floats and integers (first post)

Adam adam at monkeez.org
Sun Apr 11 17:19:30 EDT 2004


Just picking up python with Learning Python (on day 3 now - be kind) and 
have written my own small calculator script:

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 [2]
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

I've read in learning Python that the variable types look after 
themselves - "great" I think, less hassle than Java.

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?

Thanks in advance.
adam



More information about the Tutor mailing list