I'm trying to calculate square root using loops. I'm not sure what is wrong with my code, because it does not recognize the right answer.
x = 25.0
ans = 0.0
while ans**2 <= x:
ans += 0.5
if ans**2 == x:
print ans
print ans**2
else:
print "no square root"
print ans
print ans**2
When I run it, it displays following result:
no square root
5.5
30.25
and no, this is not homework, Im 32yrs old life learner
edit
Thank you all for answers. Ive modified a code a little bit, Ive changed while loop, and if statement, and my code now looks like this
x = 25.0
ans = 0.0
while ans**2 < x:
ans += 0.2
if ans**2 != x:
print "root not found"
print ans
print ans**2
else:
print "found square root"
print ans
print ans**2
And when i try to run it, it prints following
root not found
5.0
25.0
Im puzzeld