from math import sqrt def newton(num, guess): # Constant that says how close our answer has to be to right. epsilon = 0.00001 # Initialize next to the initial guess next = guess # Keep looping until next^2 gets close to num. while abs((next*next) - num) > epsilon: # This is Newton's suggestion for what value to try next. next = (next + num/next)/2 return next def main(): print("Welcome to the Newton's Method program.") number = int(input("What number do you want the root of? ")) guess = int(input("What is your initial guess? ")) # Get the answer from our newton function root = newton(number, guess) # Calculate the actual root using Python's sqrt function realroot = sqrt(number) # Print the results. print("Newtons root: ", root, " Real root: ", realroot) print("Difference is: ", abs(root-realroot))