def find_square_root(target, precision):
guess = 0
step = 1
for i in range(precision):
step = 10 ** (-i)
for _ in range(10): # 各桁で0-9まで試す
if (guess + step) ** 2 > target:
break # 大きくなりすぎたらこの桁の探索を終了
guess += step
return guess
print(find_square_root(9, 3)) # 2.999... (ほぼ3)
To embed this project on your website, copy the following code and paste it into your website's HTML: