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中运行这段代码时,什么都不会发生。它有什么问题?没有错误什么的。
发布于 2016-12-03 08:10:18
我认为,由于x增量问题,您进入了无限循环。
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只需独立于可能阻止其增量的if条件而增加x即可。
https://stackoverflow.com/questions/40945605
复制相似问题