Finding the square root using Newton's method (errors!)

前端 未结 5 1526
执念已碎
执念已碎 2020-12-11 10:06

I\'m working to finish a math problem that approximates the square root of a number using Newton\'s guess and check method in Python. The user is supposed to enter a number,

5条回答
  •  忘掉有多难
    2020-12-11 11:01

    it shouldnt have to be that complicated i wrote this up

    def squareroot(n,x):
    final = (0.5*(x+(n/x)))
    print (final)
    for i in range(0,10):
        final = (0.5*(final+(n/final)))
        print (final)
    

    or you could change it to be like this

    n = float(input('What number would you like to squareroot?'))
    x = float(input('Estimate your answer'))
    final = (0.5*(x+(n/x)))
    print (final)
    for i in range(0,10):
        final = (0.5*(final+(n/final)))
        print (final)
    

提交回复
热议问题