import math
def continued_fraction_sqrt2(iterations=20):
x = 0
for _ in range(iterations):
x = 1 / (2 + x)
result = 1 + x
return result
iterations = 20
approx = continued_fraction_sqrt2(iterations)
print(f"Approximation of sqrt(2) after {iterations} iterations: {approx:.15f}")
print(f"math.sqrt(2) = {math.sqrt(2):.15f}")
print(f"Differece = {abs(math.sqrt(2) - approx):.15f}")
aW1wb3J0IG1hdGgKIApkZWYgY29udGludWVkX2ZyYWN0aW9uX3NxcnQyKGl0ZXJhdGlvbnM9MjApOgoJeCA9IDAKCWZvciBfIGluIHJhbmdlKGl0ZXJhdGlvbnMpOgoJCXggPSAxIC8gKDIgKyB4KQoJCXJlc3VsdCA9IDEgKyB4CgkJcmV0dXJuIHJlc3VsdAppdGVyYXRpb25zID0gMjAKYXBwcm94ID0gY29udGludWVkX2ZyYWN0aW9uX3NxcnQyKGl0ZXJhdGlvbnMpCnByaW50KGYiQXBwcm94aW1hdGlvbiBvZiBzcXJ0KDIpIGFmdGVyIHtpdGVyYXRpb25zfSBpdGVyYXRpb25zOiB7YXBwcm94Oi4xNWZ9IikKcHJpbnQoZiJtYXRoLnNxcnQoMikgPSB7bWF0aC5zcXJ0KDIpOi4xNWZ9IikKcHJpbnQoZiJEaWZmZXJlY2UgPSB7YWJzKG1hdGguc3FydCgyKSAtIGFwcHJveCk6LjE1Zn0iKQ==