一句话搞定,里面用到了2个函数,range是给出1到100,sum是求和。
sum(range(1,101))
#!/usr/bin/python
#-*-coding:utf-8-*-
def Sum(max):
ret = 0
for i in range(max+1):
ret += i
return ret
if __name__ == "__main__":
print Sum(100)
# 运行结果:5050
reduce(lambda x,y:x+y,range(1,101))
sum(range(1, 101))