squareroot.py seems to read a list of eg, 20 interim values if the square root is at the average, ie if the high and low guesses are equidistant.
perhaps it should have a break after the first 'print (guess)' as in: def average(a,b):
return (a+b)/2
def squareRoot(num,low,high):
'''Finds the squareroot of num by
playing the Number guess/check strategy
by guessing over the range from "low" to high'''
for i in range(41):
guess = average(low,high)
if guess2 == num:
print(guess)
break # to return only one value for a whole number case.
elif guess2 >num: #'Guess lower."
high = guess
else: #'Guess higher.'
low = guess
print(guess)
squareRoot(100, 2,75)
squareroot.py seems to read a list of eg, 20 interim values if the square root is at the average, ie if the high and low guesses are equidistant.
perhaps it should have a break after the first 'print (guess)' as in: def average(a,b):
return (a+b)/2
def squareRoot(num,low,high):
'''Finds the squareroot of num by
playing the Number guess/check strategy
by guessing over the range from "low" to high'''
for i in range(41):
guess = average(low,high)
if guess2 == num:
print(guess)
break # to return only one value for a whole number case.
elif guess2 >num: #'Guess lower."
high = guess
squareRoot(100, 2,75)