100以内1-2+3-4+...+99-100和为:

count=1
s = 0
while count<101:
    temp=count%2
    if temp==0:
        s=s-count
    else:
        s=s+count
    count=count+1
print('100以内1-2+3-4+...+99-100和为:',s)
print('-----end-----')

 

输出结果为:

100以内1-2+3-4+...+99-100和为: -50
-----end-----



posted @ 2018-12-22 19:39  who_will  阅读(335)  评论(0编辑  收藏  举报