Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I was hopping some one could look over some coded. The Question: Elena complains that the recursive newton function in Project 2 includes an extra

I was hopping some one could look over some coded.

The Question: Elena complains that the recursive newton function in Project 2 includes an extra argument for the estimate. The functions users should not have to provide this value, which is always the same, when they call this function. Modify the definition of the function so that it uses a keyword argument with the appropriate default value, and call the function without a second argument to demonstrate that it solves this problem.

My answer:

import math

tolerance = 0.000001

def newton(n, estimate=1.0):

new_estimate = (estimate + n / estimate) / 2

difference = abs(n - new_estimate ** 2)

if difference <= tolerance:

return new_estimate

else:

return newton(n, new_estimate)

def main():

while True:

number = input("Enter a number or press * to exit ")

if number == '*':

break

number = float(number)

estimate = newton(number)

print("The program's estimate is ", estimate)

print("Python's estimate is ", math.sqrt(number))

if __name__ == "__main__":

main()

Is this right or wrong.

If wrong could you help me fix it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

Is all Internet training the same? Explain.

Answered: 1 week ago