strange behavior of math.sqrt() in new 3.0 version
David
David
Fri Dec 26 16:52:24 EST 2008
I'm a newbee trying 3.0 Please help with math.sqrt()
At the command line this function works correctly
>>> import math
n = input("enter a number > ")
s = math.sqrt(n)
An entry of 9 or 9.0 will yield 3.0
Yet the same code in a script gives an error message
Script1
import math
n = input("enter a number > ")
s = math.sqrt(n)
Traceback (most recent call last) :
File "<stdin>", line 1, in <module>
File "script1.py" line 3 in <module>
s = math.sqrt(n)
TypeError : a float is required
Entering 9 or 9.0 gives same error message.
According to the math module the results of all
functions are floats. However it says nothing about
inputs.
Strangely the above code runs fine in version 2.5 ( ? )
and will handle large integers.
I've read the documentation for 3.0 including the section
"Floating Point Arithmetic: Issues & Limitations" and it
helps nada.
More information about the Python-list
mailing list