Question: What would the code in wk4_p10.py do if the statement x = 25 were replaced by x = -25? What would have to be changed

 What would the code in wk4_p10.py do if the statement x

What would the code in wk4_p10.py do if the statement x = 25 were replaced by x = -25?

What would have to be changed to make the code in wk4_p10.py work for finding an approximation to the cube root of both negative and positive numbers? (Hint: think about changing low to ensure that the answer lies within the region being searched.)

x = 25 epsilon = 0.01 numGuesses = 0 low = 0.0 high = max(1.0, x) ans = (high + low)/2.0 while abs(ans**2 - X) >= epsilon: print('low =', low, 'high =', high, 'ans =', ans) numGuesses += 1 if ans**2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!