美文网首页
不完全立方根分治法求解

不完全立方根分治法求解

作者: 大师的学徒 | 来源:发表于2020-03-15 01:31 被阅读0次
    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 ! ")
    

    相关文章

      网友评论

          本文标题:不完全立方根分治法求解

          本文链接:https://www.haomeiwen.com/subject/gowashtx.html