Ask Question
2 November, 06:45

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

+2
Answers (1)
  1. 2 November, 08:55
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers