私は数の平方根を無差別に計算するプログラムを書いています。しかし、特定の数字(毎回同じ)。ここでPython Skips Numbers
はコードです:
toCalc = 3
guess = toCalc
toCalc = round(toCalc, 2)
while 1+1==2:
print "Trying ", guess, "..."
calc = guess * guess
calc = round(calc, 2)
print calc
guess = guess - 0.01
if calc == toCalc:
break
そして、ここでは、出力されます。
Trying 1.22 ...
1.49
Trying 1.21 ...
1.46
Trying 1.2 ...
1.44
Trying 1.19 ...
1.42
Trying 1.18 ...
1.39
Trying 1.17 ...
1.37
Trying 1.16 ...
1.35
Trying 1.15 ...
1.32
Trying 1.14 ...
1.3
Trying 1.13 ...
1.28
Trying 1.12 ...
1.25
Trying 1.11 ...
1.23
Trying 1.1 ...
1.21
Trying 1.09 ...
1.19
Trying 1.08 ...
1.17
Trying 1.07 ...
1.14
Trying 1.06 ...
1.12
Trying 1.05 ...
1.1
Trying 1.04 ...
1.08
Trying 1.03 ...
1.06
Trying 1.02 ...
1.04
Trying 1.01 ...
1.02
Trying 1.0 ...
1.0
Trying 0.99 ...
0.98
Trying 0.98 ...
0.96
Trying 0.97 ...
0.94
Trying 0.96 ...
0.92
Trying 0.95 ...
0.9
Trying 0.94 ...
0.88
Trying 0.93 ...
0.86
Trying 0.92 ...
0.85
Trying 0.91 ...
0.83
数の推測である "しよう" の後CALCと番号である "しよう" の下に。
なぜmath.sqrtを使用しないのですか –
あなたの質問は何ですか? –
あなたのアルゴリズムは動作しません。より良いものを探してみてください。 – Daniel