Python Code - Babylonian Style

import math # ---------------------------------------------------------- # ---- Babylonian (Video's) square root algorithm # ---- # ---- we are estimating the square root of "num". "loop" # ---- is the number of times to loop thru the calculation # ---- to improve the accuracy. "estimate" is the # ---- estimated square root of "num". # ---------------------------------------------------------- def video_square_root_algorithm(num,loop): # ---- generate algorithm seed (nearest perfect square) # ---- (the Babylonians used a table to do this) nps_root,nps = nearest_perfect_square(num) # ---- loop to increase accuracy estimate = nps_root # initial estimated square root print() print(f'original estimate = {estimate}') for _ in range(loop): new_estimate = estimate + \ (num - (estimate*estimate))/(2*estimate) estimate = new_estimate print() print(f'new estimate = {new_estimate}') print(f'math.sqrt = {math.sqrt(num)}') return estimate