categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the algorithm for finding a square root using the Babylonian method. Its operation, time complexity, and usefulness. Below you will also find ready-to-use code that you can copy if needed.
Code:
liczba = 49
dokladnosc = 0.5
pierwiastek = liczba / 2
while pierwiastek**2 < liczba - dokladnosc or pierwiastek**2 > liczba + dokladnosc:
pomocnicza = liczba / pierwiastek
pierwiastek = (pierwiastek + pomocnicza) / 2
print(pierwiastek)
"""for loop iteration 1
pomocnicza = 2
pierwiastek = 13.25
for iteration 2
pomocnicza = 3.63
pierwiastek = 8.43
for iteration 3
pomocnicza = 5.81
pierwiastek = 7.12
"""
Video:
Thank you for reading!
Read more