the-honk/languages/python/calculators/SQRT.py

19 lines
340 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
2021-07-10 11:23:46 +00:00
def sqrt(x):
a = 2
while abs((a - (x / a))) > 1:
a = (a + (x / a)) / 2
2021-07-16 16:25:04 +00:00
return int(a)
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)