float(line)
does not convert in-place. It returns the float
value. You need to assign it back to a float variable.
float_line = float(line)
UPDATE: Actually a better way is to first check if the input is a digit or not. In case it is not a digit float(line)
would crash. So this is better -
float_line = None
if line.isdigit():
float_line = float(line)
else:
print 'ERROR: Input needs to be a DIGIT or FLOAT.'
Note that you can also do this by catching ValueError
exception by first forcefully converting line
and in except
handle it.
try:
float_line = float(line)
except ValueError:
float_line = None
Any of the above 2 methods would lead to a more robust program.