# 计算从1到100的自然数之和 # sum = (1+100)/2*100 sum = 0 for i in range(1,101): sum += i print(sum)
def sum(n): sum = 0 for i in range(1, n+1): sum += i return sum print(sum(100))