Home / Questions / Part 1 Encapsulate the following Python code from Section 7.5 in a function named my_sqrt that takes
Part 1
Encapsulate the following Python code from Section 7.5 in a function named my_sqrt that takes a as a parameter, chooses a starting value for x, and returns an estimate of the square root of a.
while True:
y = (x + a/x) / 2.0
if y == x:
break
x = y
Part 2
Write a function named test_sqrt that prints a table like the following using a while loop, where "diff" is the absolute value of the difference between my_sqrt(a) and math.sqrt(a).
a = 1 | my_sqrt(a) = 1 | math.sqrt(a) = 1.0 | diff = 0.0
a = 2 | my_sqrt(a) = 1.41421356237 | math.sqrt(a) = 1.41421356237 | diff = 2.22044604925e-16
a = 3 | my_sqrt(a) = 1.73205080757 | math.sqrt(a) = 1.73205080757 | diff = 0.0
a = 4 | my_sqrt(a) = 2.0 | math.sqrt(a) = 2.0 | diff = 0.0
a = 5 | my_sqrt(a) = 2.2360679775 | math.sqrt(a) = 2.2360679775 | diff = 0.0
a = 6 | my_sqrt(a) = 2.44948974278 | math.sqrt(a) = 2.44948974278 | diff = 0.0
a = 7 | my_sqrt(a) = 2.64575131106 | math.sqrt(a) = 2.64575131106 | diff = 0.0
a = 8 | my_sqrt(a) = 2.82842712475 | math.sqrt(a) = 2.82842712475 | diff = 4.4408920985e-16
a = 9 | my_sqrt(a) = 3.0 | math.sqrt(a) = 3.0 | diff = 0.0
Modify your program so that it outputs lines for a values from 1 to 25 instead of just 1 to 9.
You should submit a script file and a plain text output file (.txt) that contains the test output. Multiple file uploads are permitted.
Your submission will be assessed using the following Aspects.
Apr 02 2020 View more View Less
Business LawIn the following situations, two parties claim the same goods. Discuss who is most likely to prevail in each circumstance. Explain the basis for your response...
Aug 03 2020Hi-Tek Manufacturing Inc. makes two types of industrial component parts—the B300 and the T500. An absorption costing income statement for the most recent period is shown ...
Sep 09 2020(Evaluating liquidity) The Tabor Sales Company had a gross profit margin (gross profits divided by sales) of 30.0 percent and sales of $9.0 million last year. Seven...
Apr 04 2020On February 1, Clovis Wilson Law Firm contracted to provide $3,000 of legal services for the next three months and received $3,000 cash from the client. Assuming Wilson r...
Apr 21 2020Which of the following is a measure of profitability? a. Quick (acid-test) ratio b. Net sales c. Inventory turnover d. Return on assets (ROA)
Aug 24 2020Question 1 (40 marks) (a) Explain how cellular layout can facilitate lean production. (5 marks) (b) A manufacturing company is considering to adopt cellular layout to fac...
Jun 06 2021How are LLCs and LLPs related to the other forms of organization?Here is a tip:The owners of many businesses desire both tax benefits and limited liability.
Apr 23 2021Was that great idea your's?
Aug 23 2021COMPUTER ANALYSIS OF STRUCTURES AND STRUCTURAL DYNAMICS - 2019 Assignment No. 2 Q.1: Taking nodes at A, B C and D of the 2D plane frame shown in the figure, identify th...
May 24 2020Kelsey Nicolosi is the general manager of a multiplex movie theater. In order to boost profits, Ms. Nicolosi is considering a two-for-one promotion, in which any customer...
Jul 23 2021