cube = 8120601
epsilon = 0.01
low = 0.0
high = cube
guess = (high + low)/2
num_guesses = 0
# while abs(guess ** 3 - cube) >= epsilon and guess < cube:
if cube > 1:
while abs(cube - guess**3) >= epsilon:
if guess**3 > cube:
high = guess
else:
low = guess
guess = (high + low)/2
num_guesses += 1
print('Guesses %d times.' % num_guesses)
print(guess, "is close to the cube root of", cube)
elif cube = 1:
print("What the hell is wrong with you ! ")
网友评论