JPHamlett
2014-09-14 20:34:51
This code here keep going into an endless loop and I cannot figure out why
And yes I am aware of math.sqrt, I'm not alowd to use it
Here's some debug
edit: Made a stupid grammatical error.
And yes I am aware of math.sqrt, I'm not alowd to use it
def sqr(n):
guess = n/4
print("Creating a guess, we will use: ")
while abs(n-guess) >.00001:
avgDeter = n/guess
print("new avg determinant: " + str(avgDeter))
guess = (guess + avgDeter)/2
print ("Guess failed....retrying with: " + str(guess))
return 0
Here's some debug
Guess failed....retrying with: 5.001524390243903Count = 1
new avg determinant: 4.998476074367571
Guess failed....retrying with: 5.000000232305737Count = 2
new avg determinant: 4.999999767694273
Guess failed....retrying with: 5.000000000000005Count = 3
new avg determinant: 4.999999999999995
Guess failed....retrying with: 5.0Count = 4
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 5
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 6
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 7
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 8
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 9
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 10
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 11
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 12
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 13
new avg determinant: 5.0
Guess failed....retrying with: 5.0Count = 14
new avg determinant: 5.0
edit: Made a stupid grammatical error.