【发布时间】:2019-12-13 18:26:09
【问题描述】:
for 循环可以运行 33 次,但不能运行超过它。 我必须运行它 100 次。 谢谢你! for 循环必须运行 100 次,最后打印 "a" "profit" 和 "total"
a = 0
pluser = 0.01
total = 0
profit = 0
lasta = 0
lastProfit = 0
lastTotal = 0
counter = 0
for i in range (100):
lasta = a
lastTotal = total
lastProfit = lasta * 14 - lastTotal
a += pluser
total += a
profit = a * 14 - total
while (profit <= lastProfit):
pluser += 0.01
a += pluser
total += a
profit = a * 14 - total
counter += 1
print(a)
print(total)
print(profit)
print(counter)
【问题讨论】:
-
它卡在了 while 循环中,因为
profit在第 33 次迭代时总是递减。您正在从中减去total。 -
请注意,
total在while 循环中可能大于14a,而且total的增长速度可能快于a。
标签: python loops for-loop compiler-errors qtquick2