我正在嘗試乘以從 while 回圈中獲得的數字。像 1.1 * 1.2 * 1.3 ... * 2 - 數字從 1.1 開始并在 2 處停止我已經這樣做了,但它給了我 4.41 而不是 67.04,有什么問題?我需要使用for回圈來撰寫它嗎?腳本:
count = 1.1
while count < 2.1:
print(count)
count = 0.1
print(round(count * count, 3))
uj5u.com熱心網友回復:
out = 1
for i in range(11,21):
out *= i/10
print(out)
輸出:
67.04425728
uj5u.com熱心網友回復:
我添加了一個 final_product 變數,它將乘以每個更新的計數值,也許這可以幫助:
count = 1.1
final_product = 1
while count < 2.1:
print(count)
final_product*=count
count = 0.1
print(round(final_product, 2))
你做的一切都很完美,但你需要添加一些東西來捕獲新的更新值(乘以 0.1)并乘以自身以獲得最終產品,即 67.04。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/368660.html
上一篇:使用回圈列印圖案
下一篇:關于回圈的c程式
