Indentation in Python is significant: it controls what is and isn't in a block of code.
All the contiguous code indented by the same amount (or more) is part of the same code block:
while foo == bar:
Part of loop
if (foo + bar == foobar:
Still part of loop
Not part of loop - executed once the loop exits.
So your lack of indentation on the
return
statement means it isn't a part of the
if
or the
while
.
As a result, there is no way out of the loop and your app never does anything.
Indent it properly, and it should start to work:
def mysqrt(a):
while True:
x=a/2
y=(x+a/x)/2
if abs(y-x)<epsilon:
return(y)
However, you should note that you don't alter
a
or
epsilon
inside the loop, so either it will exit after the first iteration, or never ...