What is a float?


what is a float

I typed this for function imports
from math import sqrt
module = raw_input("Enter a number:")
print sqrt("module")

could you help me out it showed me:
Traceback (most recent call last):
File "python", line 4, in
TypeError: a float is required

Replace this line with your code.


Any number with a decimal fraction is a float. Strictly speaking this only relates to computers and the binary number system.

Computers have built in math processors that do all the heavy lifting, and there is a lot, when computing decimal fractions in a base 2 arithmetic system. There are no decimal points in binary. The special math that had to be designed to deal with this problem is called floating point arithmetic. That's where we get the term, float.


what do i type in then


No quotes on variable names.


i did that i typed : print sqrt(module)


module is still a string as Python interprets it. That's what we get from raw_input() (well not exactly, but let's just go along with the notion, for now). We need to convert the number to an int() or a float(), as in,

print sqrt(float(module))


thanks a lot it worked out. the new code was:
from math import sqrt
module = raw_input("Enter a number:")
print sqrt(float(module))

thanks again


Are you clear on what constitutes a float. We could add to your knowledge base...