不完全立方根穷举法求解

2020-03-15  本文已影响0人  大师的学徒
cube = 8120601
epsilon = 0.01
guess = 0.0
increment = 0.0001
num_guesses = 0
# while abs(guess ** 3 - cube) >= epsilon and guess < cube:
while cube - guess**3 >= epsilon:
    guess += increment
    num_guesses += 1
print('Guesses %d times.' % num_guesses)
print(guess,"is close to the cube root of", cube)

上一篇下一篇

猜你喜欢

热点阅读