用于记录自己写的,或学习期间看到的不错的,小程序,持续更新......
【例001】计算:1-2+3-4..+199-200值
复制代码 代码如下:
sum1 = 0
sum2 = 0
for i in range(1,200,2): #计算1+3+5+7...199
sum1 +=i
print sum1
for i in range(-200,0,2): #计算-2+(-4)+(-6)...+(-200)
sum2 +=i
print sum2
print "The total of 1-2+3-4..+199-200 is: ", sum1+sum2
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8