Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def square_root(a):
- if a <= 8:
- x = 3
- else:
- x = float(((a/2)/2)/2)
- epsilon = 0.0000001
- while True:
- y = (x +a/x) / 2.0
- if abs(y-x) < epsilon:
- break
- x = y
- print ""
- print "My guess is that the square root of",a,"is",y
- """ Guesses square root of 'a' based upon Newtons method which uses
- y = (x +a/x) / 2
- then repeats with x=y until y and x even out
- """
Advertisement
Add Comment
Please, Sign In to add comment