The following is pseudocode to compute the square root of an inputted number, called number. EPSILON = 1.0e-14 answer = “yes” while answer[0] equals “Y” or answer[0] equals “y” prompt “Enter a number...


The following is pseudocode to compute the square root of an inputted number, called number.
EPSILON = 1.0e-14
answer = “yes”
while answer[0] equals “Y” or answer[0] equals “y”
prompt “Enter a number to be square rooted: “
input number
approximation = 1
iteration = 0
while absolute value of approximation * approximation minus number
is greater than EPSILON
approximation = 0.5 * (approximation + number / approximation)
iteration++
output “The square root of “ number “ is “ approximation
output “The number of iterations needed were “ iteration
prompt “Do you wish to continue?”
input answer
Translate the above psuedecode into Python and use it to approximate various square roots.
You program should produce the following output below. Be sure to include a docstring
comment in the beginning




>>><br>== RESTART : F:/CP1/Labs/Lab3/square_root.py<br>This program calculates the square root of an inputted number<br>and the number of iterations that the algorithm took to reach<br>a degree of accuracy of le-14.<br>Enter a nonnegative number: 24<br>The square root of 24.0 is 4.898979485566356.<br>The number of iterations needed were 7.<br>Do you wish to continue (y/n) ? y<br>Enter a nonnegative number: 36<br>The square root of 36.0 is 6.0.<br>The number of iterations needed were 7.<br>Do you wish to continue (y/n) ? y<br>Enter a nonnegative number: -3<br>Please enter a nonnegative number: 0<br>The square root of 0.0 is 5.960464477539063e-08.<br>The number of iterations needed were 24.<br>Do you wish to continue (y/n) ? y<br>Enter a nonnegative number: 2<br>The square root of 2.0 is 1.414213562373095.<br>The number of iterations needed were 5.<br>Do you wish to continue (y/n) ? n<br>>>><br>

Extracted text: >>> == RESTART : F:/CP1/Labs/Lab3/square_root.py This program calculates the square root of an inputted number and the number of iterations that the algorithm took to reach a degree of accuracy of le-14. Enter a nonnegative number: 24 The square root of 24.0 is 4.898979485566356. The number of iterations needed were 7. Do you wish to continue (y/n) ? y Enter a nonnegative number: 36 The square root of 36.0 is 6.0. The number of iterations needed were 7. Do you wish to continue (y/n) ? y Enter a nonnegative number: -3 Please enter a nonnegative number: 0 The square root of 0.0 is 5.960464477539063e-08. The number of iterations needed were 24. Do you wish to continue (y/n) ? y Enter a nonnegative number: 2 The square root of 2.0 is 1.414213562373095. The number of iterations needed were 5. Do you wish to continue (y/n) ? n >>>

Jun 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here