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.
y = (x + a/x) / 2.0
if y == x:
x = y
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.
An n-type piece of silicon experiences an electric field equal to 0.1 V/m.(a) Calculate the velocity of electrons and holes in this material.(b) What doping level is nec...Jul 27 2020
Generally, an organization will institute a layoff whenA. It cannot reduce its costs by any other means.B. The organization has identified low-performing employees.C. An ...May 29 2020
Compare and contrast two of these three methodologies for conducting a process hazard analysis:HAZOP StudyWhat-If AnalysisFailure Mode and Effects AnalysisBe sure to disc...Mar 21 2020
Solve for the Principal Value(s) of x. You do not need to show your work. Give your answer(s) to this problem in RADIANS in terms of p. sin3x = sin xMar 25 2020
Debenture is also named as: (A) Share (B) Bond (C) Reserve (D) EquityApr 12 2018
The pilot of a light plane heads due north at an air speed of 400 km/h. A wind is blowing from the west at 60 km/h. (a) What is the plane’s velocity with respect to the ...May 13 2020
Upload US crime data and compare the burglary counts for the states of Hawaii, California, Arizona and Nevada. Your job is to identify which of the three states is most c...Apr 18 2020
Elizabeth short sold 400 shares of stock at $72 a share. One month later, she covered the short at a price of $68. What was her total dollar return on this investment?A) ...Apr 08 2020
Consider an economy in which all taxes are autonomous and the following values oof autonomous consumption, planned investment, government expenditure, autonomous taxes, a...Apr 23 2020
What should be included in the minimum qualifications section of a job description?A) The basic standards a job applicant must have to be considered for the jobB) The 3-5...Jan 24 2020