1. List item
sum = 0
i = 1
while i <= 99:
if i % 2 ==0:
sum -= i
else:
sum += i
i += 1
print(sum)
2. List item
sum = 1
i,j = 2,3
while j <= 99:
sum1 = i - j
sum -= sum1
i += 2
j += 2
print(sum)
求1-2+3-4+5 ... 99的所有数的和
最新推荐文章于 2023-07-18 22:55:34 发布