Python implementation of Babylonian Method – method to calculate square root of positive numbers.

IN 3 0.0000000001 OUT sqrt( 3.0 ) = 0.3 sqrt( 3.0 ) = 5.15 sqrt( 3.0 ) = 2.86626213592233 sqrt( 3.0 ) = 1.956460731776899 sqrt( 3.0 ) = 1.74492093914502 sqrt( 3.0 ) = 1.7320982711195376 sqrt( 3.0 ) = 1.7320508082191837

# © 2018 TheFlyingKeyboard and released under MIT License # theflyingkeyboard.net number = float(input("Enter number to square root: ")) precision = float(input("Enter precision of method: ")) if (number < 0): print("number must be >= 0") elif (number == 0): print("sqrt(0) = 0") else: x = number / 10; y = number / x; counter = 0 while (x - y > precision or counter <= 1): print("sqrt(", number, ") = ", x) x = (x + y) / 2 y = number / x counter += 1

Python Babylonian Method – SQRT()