Ask Question

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

+1
Answers (1)
  1. 2 February, 04:26
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers