day01每日一行
普通使用控制结构
# 计算从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))
# 计算从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))