python 计算等差数列和的两种循环方式

magicandy 2020-01-11

计算 1~100 的和 5050

while 循环:

i, s = 0, 0

while i < 101:
    s += i
    i += 1
    
print(s)

for 循环:

s = 0

for i in range(101):
    s += i
    
print(s)

相关推荐