Untitled
Aproxmation sqrtunknown
python
2 years ago
569 B
10
Indexable
def sqrt_approximation(x: float): # This function calculates an approximation of the square root of the input x # using the formula (x + 17/x) * 0.5, where 0.5 is the initial guess. approximation = 0.5 formula_result = (x + 17 / x) return approximation * formula_result result1 = sqrt_approximation(20) result2 = sqrt_approximation(result1) result3 = sqrt_approximation(result2) result4 = sqrt_approximation(result3) print(f"{float(result1):.3f}") print(f"{float(result2):.4f}") print(f"{float(result3):.6f}") print(f"{float(result4):.8f}")
Editor is loading...