求偶数的和:
sum = 0 for i in range(1,101): if i % 2 == 0: sum = sum + i print(sum)
输出结果为:2550
求奇数的和:
sum = 0 for i in range(1,101): if i % 2 == 1: sum = sum + i print(sum)
输出结果为:2500
2024-04-07 21:58:45
求偶数的和:
sum = 0 for i in range(1,101): if i % 2 == 0: sum = sum + i print(sum)
输出结果为:2550
求奇数的和:
sum = 0 for i in range(1,101): if i % 2 == 1: sum = sum + i print(sum)
输出结果为:2500