def solution(number):
x = 0
total = 0
while x < number:
if x % 3 == 0 or x % 5 == 0:
total = total + x
x = x + 1
print total
return total
solution(10)
你好,当我通过IDE运行此代码时,什么也没有发生。 它有什么问题?没有任何错误或任何事情。没有功能输出
'x = x + 1'位于if区块内部,所以如果条件为false,'x'永远不会增加,并且会得到一个无限循环。 – JJJ