求1~n内的数字累加和sum
以下题设n=100
def sum_n(n):
sum=0
for i in range(1,n+1):
sum += i
return sum
m = sum_n(100)
print('其和为:', m)
求1~n内的数字累加和sum
以下题设n=100
def sum_n(n):
sum=0
for i in range(1,n+1):
sum += i
return sum
m = sum_n(100)
print('其和为:', m)