怎么用Python中的for循环求1+2+3+…+100的值?

怎么用Python中的for循环求1+2+3+…+100的值?
2024-11-18 10:58:41
推荐回答(3个)
回答1:

num = 0
for i in range(1,101):
num += i
print num

回答2:

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

回答3:

def getsum=(n):
sum=0
for i in range(n):
sum+=(i+1)
return sum

getsum(100)