求和 1+2+3+4+5+6+7+8......+100=?
方法一:
sum=0
for i in range(1,101,1):
sum=sum+i
print(sum)
运行以上代码,显示结果:
方法二:
sum=0
count=1
while count<=100:
sum=sum+count
count=count+1
print(count)
print(sum)
运行以上代码,显示结果:
方法一:
sum=0
for i in range(1,101,1):
sum=sum+i
print(sum)
运行以上代码,显示结果:
方法二:
sum=0
count=1
while count<=100:
sum=sum+count
count=count+1
print(count)
print(sum)
运行以上代码,显示结果: