Guest User

Untitled

a guest
Feb 17th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. x = 12345
  2. epsilon = 0.01
  3. numGuesses = 0
  4. low = 0.0
  5. high = x
  6. ans = (high + low)/2.0
  7. while abs(ans**2 - x) >= epsilon and ans <= x:
  8. #print low, high, ans
  9. numGuesses += 1
  10. if ans**2 < x:
  11. low = ans
  12. else:
  13. high = ans
  14. ans = (high + low)/2.0
  15. print 'numGuesses =', numGuesses
  16. print ans, 'is close to square root of', x
Advertisement
Add Comment
Please, Sign In to add comment