Ask Question
20 September, 03:25

Package Newton's method for approximating square roots (Case Study: Approximating Square Roots) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key

+4
Answers (1)
  1. 20 September, 06:54
    0
    def newton (n):

    #Define the variables.

    t = 0.000001

    esti = 1.0

    #Calculate the square root

    #using newton method.

    while True:

    esti = (esti + n / esti) / 2

    dif = abs (n - esti * * 2)

    if dif < = t:

    break

    #Return the result.

    return esti

    #Define the main function.

    def main ():

    #Continue until user press enters.

    while True:

    try:

    #Prompt the user for input.

    n = int (input ("Enter a number (Press Enter to stop) : "))

    #display the results.

    print ("newton = %0.15f" % newton (n))

    except:

    return

    #Call the main function.

    main ()
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Package Newton's method for approximating square roots (Case Study: Approximating Square Roots) in a function named newton. This function ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers