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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education