the-honk/python/calculators/Babylonian Square Root.py
2024-10-09 18:02:48 +01:00

18 lines
430 B
Python

"""
A square root calculator based on the Babylonian's approach!
Created as a part of my Royal Institute masterclass
"""
from _helpers import intInput
def sqrt(number):
initialGuess = 2
while abs(initialGuess - (number / initialGuess)) > 1:
initialGuess = (initialGuess + (number / initialGuess)) / 2
return int(initialGuess)
num = intInput('Please input a number! (:')
res = sqrt(num)
print()
print('Square Root:', res)