Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created February 16, 2023 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/760188ca9b0d78782a41fe25ca975a82 to your computer and use it in GitHub Desktop.
Save thinkphp/760188ca9b0d78782a41fe25ca975a82 to your computer and use it in GitHub Desktop.
#
# Square Root Babylonian Method
# @Adrian Statescu
#
def sqrt_babylonian(n):
x = n
y = 1.0
eps = 0.000001
while x - y > eps:
x = (x + y) / 2
y = n / x
return x
def main():
n = int(input("n = "))
r = sqrt_babylonian(n)
print("sqrt(%d) = %f" % (n, r))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment