Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

input a = ('Square root of what?a') def my_sqrt(a): a = float(a) # Convert to float x = a / 2 # a rough estimate

input

a = ('Square root of what?\a')

def my_sqrt(a): a = float(a) # Convert to float x = a / 2 # a rough estimate of sqrt, half the input. i = 0 # initialize counter while True: y = (x + a/x) / 2.0 if y == x: break x = y return y

import math a=float(a) math.sqrt(a)

Output

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

Question

Does the submission include a my_sqrt function that takes a single argument and includes the while loop from the instructions?

Does the my_sqrt function initialize x and return its final value?

Does the test_sqrt function print a values from 1 to 25?

Does the test_sqrt function print the values returned by my_sqrt for each value of a?

Does the test_sqrt function print correct values from math.sqrt for each value of a?

Does the test_sqrt function print the absolute value of the differences between my_sqrt and math.sqrt for each value of a?

Does the my_sqrt function compute values that are almost identical to math.sqrt ("diff" less than 1e-14)?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions

Question

Prepare an electronic rsum.

Answered: 1 week ago

Question

Strengthen your personal presence.

Answered: 1 week ago

Question

Identify the steps to follow in preparing an oral presentation.

Answered: 1 week ago