Restructure Newton's method (Case Study: Approximating Square Roots) by decomposing it into three cooperating functions: newton, limitReached, and improveEstimate. The newton function can use either the recursive strategy of Project 2 or the iterative strategy of the Approximating Square Roots Case Study. The task of testing for the limit is assigned to a function named limitReached, whereas the task of computing a new approximation is assigned to a function named improveEstimate. Each function expects the relevant arguments and returns an appropriate value. An example of the program input and output is shown below: Enter a positive number or enter/return to quit: 2 The program's estimate is 1.4142135623746899 Python's estimate is 1.4142135623730951 Enter a positive number or enter/return to quit

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question

This is the question: 

Restructure Newton's method (Case Study: Approximating Square Roots) by decomposing it into three cooperating functions: newton, limitReached, and improveEstimate.

The newton function can use either the recursive strategy of Project 2 or the iterative strategy of the Approximating Square Roots Case Study. The task of testing for the limit is assigned to a function named limitReached, whereas the task of computing a new approximation is assigned to a function named improveEstimate. Each function expects the relevant arguments and returns an appropriate value.

An example of the program input and output is shown below:

Enter a positive number or enter/return to quit: 2

The program's estimate is 1.4142135623746899

Python's estimate is 1.4142135623730951

Enter a positive number or enter/return to quit

 

I will attatch my code as an image. 

I have written the code and I really do not know why the program is not accepting it, even though my code returns exactly what the question's example did. 

I will also attatch the error the program gives me. 

3
4 import math
6 while True:
7
while True:
x = input("Enter a positive number or press enter/return to quit: ")
if not x.replace('.', '', 1).isdigit():
9.
10
break
11
X =
float(x)
12
break
13
14
15
tolerance = 0.000001
16
estimate = 1.0
17
18
19
while True:
estimate = (estimate + x / estimate) / 2
difference = abs(x
if difference <= tolerance:
break
20
21
- estimate ** 2)
22
23
if difference > tolerance:
print("Please input a number.")
24
25
26
break
27
print("The program's estimate is", estimate)
print("Python's estimate is
28
29
math.sqrt(x))
30
31
if x == "enter":
32
break
33
Transcribed Image Text:3 4 import math 6 while True: 7 while True: x = input("Enter a positive number or press enter/return to quit: ") if not x.replace('.', '', 1).isdigit(): 9. 10 break 11 X = float(x) 12 break 13 14 15 tolerance = 0.000001 16 estimate = 1.0 17 18 19 while True: estimate = (estimate + x / estimate) / 2 difference = abs(x if difference <= tolerance: break 20 21 - estimate ** 2) 22 23 if difference > tolerance: print("Please input a number.") 24 25 26 break 27 print("The program's estimate is", estimate) print("Python's estimate is 28 29 math.sqrt(x)) 30 31 if x == "enter": 32 break 33
O out of 3 checks passed. Review the results below for more details.
Checks
Unit Test
Incomplete
The newton function returns the square root of 'x'
Unit Test
Incomplete
The limitReached function returns True if the estimate is within the
tolerance, if not, False
Unit Test
Incomplete
>
The improveEstimate function returns an improved estimate
Transcribed Image Text:O out of 3 checks passed. Review the results below for more details. Checks Unit Test Incomplete The newton function returns the square root of 'x' Unit Test Incomplete The limitReached function returns True if the estimate is within the tolerance, if not, False Unit Test Incomplete > The improveEstimate function returns an improved estimate
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning