Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 28 Online
OpenStudy (anonymous):

x = 25 epsilon = 0.01 numGuesses = 0 ans = 0.0 while abs(ans**2 - x) >= epsilon and ans <= x: ans += 0.00001 numGuesses += 1 print 'numGuesses =', numGuesses if abs(ans**2 - x) >= epsilon: print 'Failed on square root of', x else: print ans, 'is close to square root of', x The way I am understanding this line of code is that in the while line of code, abs(ans**2 - x) >= epsilon, this statement is false so the while operation terminates before it can continue right? But both epsilon and ans have to be true for it to loop. Please someone help me out on this one.

OpenStudy (anonymous):

I finally figured it out. abs will make a -25.0 = 25.0

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!