对已有的计算 0 - 100 的while循环进行改造,通过增加 continue 语句,使得只计算奇数的和:
结果也是2500,不知道能不能如下结构写:
sum = 0
x = 1
n = 0
while True:
sum = sum + x
x = x + 2
n = n + 1
if n < 50:
continue
else:
break
print(sum)
结果也是2500,不知道能不能如下结构写:
sum = 0
x = 1
n = 0
while True:
sum = sum + x
x = x + 2
n = n + 1
if n < 50:
continue
else:
break
print(sum)
2017-06-11
举报