the-honk/python/calculators/Babylonian Square Root.py

19 lines
430 B
Python
Raw Normal View History

2021-08-26 01:42:17 +00:00
"""
A square root calculator based on the Babylonian's approach!
Created as a part of my Royal Institute masterclass
"""
from _helpers import intInput
2022-01-11 18:14:41 +00:00
def sqrt(number):
initialGuess = 2
while abs(initialGuess - (number / initialGuess)) > 1:
initialGuess = (initialGuess + (number / initialGuess)) / 2
return int(initialGuess)
2021-07-10 11:23:46 +00:00
2021-08-26 01:42:17 +00:00
num = intInput('Please input a number! (:')
res = sqrt(num)
print()
print('Square Root:', res)