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

Alan Gauld alan.gauld at blueyonder.co.uk
Mon Apr 12 14:54:24 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 [2]
> num2 = long(arg3)

If you convert to floats instead of longs it will work.
( Within the limited accuracy of floating point representation
  on a computer)

> 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?

Alternatively you can try testing to see if the number read is a float
- check if it has a decimal point is one way.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list