I'm trying to program a function to compute Newton's method. Expect I keep getting an error in my code.
This is the prompt that I was given to write a code for
And this is my code that I have written down
import math
def newton(x):
tolerance = 0.000001
estimate = 1.0
while True:
estimate = (estimate + x / estimate) / 2
difference = abs(x - estimate ** 2)
if difference <= tolerance:
break
return estimate
def main():
while True:
x = input("Enter a positive number or enter/return to quit: ")
if x == '':
break
x = float(x)
print("The program's estimate is", newton(x))
print("Python's estimate is ", math.sqrt(x))
main()
And it seems to be working but I keep getting this error when I run checks on Cengage
I'm not really sure what it means because my code seems to be running just fine. Can anyone help explain this?