Ask
your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
41 Online
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.
Still Need Help?
Join the QuestionCove community and study together with friends!
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!
Join our real-time social learning platform and learn together with your friends!
Latest Questions
Z1ah:
Discuss the impact of the Industrial Revolution on social structures in 19th-century Europe.
Z1ah:
Explain the process of photosynthesis, including the formula for photosynthesis, the main components involved, and the significance of this process for both
Countless7Echos:
Bob ross really got my painter ego on, touching paper again yips :3 how I do (it'
2 hours ago
9 Replies
1 Medal
2 hours ago
1 Reply
1 Medal
46 minutes ago
13 Replies
5 Medals