求出1-2+3-4+5------100求和

n = 1
sum = 0
while n < 100:
    temp = n % 2
    if temp == 0:
        sum = sum - n
    else:
        sum = sum + n
    n = n + 1
print(sum)

 

posted @ 2016-12-10 09:02  打不死的--蟑螂  阅读(526)  评论(0编辑  收藏  举报