Convert Newton's method for approximating square roots in Project 1 to a recursive function named newton . (Hint: The estimate of the square root should be passed as a second argument to the function.)
Convert Newton's method for approximating square roots in Project 1 to a recursive function named newton . (Hint: The estimate of the square root should be passed as a second argument to the function.)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
100%
The instructions are on the left, the code is on the right.

Transcribed Image Text:Instructions
newton.py
+
1 # Modify the code below
2 II I| ||
Convert Newton's method for approximating square roots in Project
3 File: newton.py
1 to a recursive function named newton . (Hint: The estimate of the
4 Project 6.1
5 Compute the square root of a number (uses function with loop).
6 1. The input is a number, or enter/return to halt the
input process.
8 2. The outputs are the program's estimate of the square root
square root should be passed as a second argument to the
function.)
7
An example of the program input and output is shown below:
9
using Newton's method of successive approximations, and
Python's own estimate using math.sqrt.
10
11 "|
Enter a positive number or enter/return to quit: 2
12
13 import math
The program's estimate is 1.4142135623746899
14
Python's estimate is
1.4142135623730951
15
Enter a positive number or enter/return to quit
16 # Initialize the tolerance
17 TOLERANCE = 0.000001
18
19 def newton (x):
20
"I"Returns the square root of x."""
21
# Perform the successive approximations
estimate = 1.0
23
while True:
(estimate + x / estimate) / 2
estimate ** 2)
24
estimate =
difference = abs(x
if difference <= TOLERANCE:
25
26
27
break
28
return estimate
29
30 def main():
31
I" I|"Allows the user to obtain square roots."""
32
while True:
33
# Receive the input number from the user
34
x = input("Enter a positive number or enter/return to quit: ")
35
if x == "":
36
break
x = float(x)
# Output the result
print("The program's estimate is", newton(x))
print("Python's estimate is
37
38
39
40
", math.sqrt(x))
41
42 if --name_-
%3D
'-_main__":
==
43
main()
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY