Answer:
import math
#Initialize tolerance
tolerance = 0.000001
def newton(x):
""" Returns the square root of x """
#Performs the successive approximations
estimate = 1.0
while True:
estimate = (estimate + x / estimate) / 2
difference = abs(x - estimate ** 2)
if difference <= tolerance: # Break out of loop if difference is less than tolerance
break
return estimate # While the difference value is > TOLERANCE, the process continues
def main():
"""Allows the user to obtain square roots."""
while True:
#Receive the input number from the user
x = input("Enter a positive number or enter/return to quit: ")
if x == "": #if user presses "Enter" then exit the program
break # Otherwise, continue the process of allowing new numbers
x = float(x)
#Output the result
print("The programs estimate of the square root of ", x, "is ", round(newton(x),2))
print("Python's estimate: ", math.sqrt(x))
main()