用for循环计算(1-3+5-7...99)的结果(两种方法)

1)
sum=0
count=1
for i in range(1,100,2):
    if count % 2==0:
        sum = sum - i
    else:
        sum = sum + i
    count = count+1
print(sum)

 


2) sum = 0 count = 1 for i in range(1,100,2): sum = sum + i*count count = -count print(sum)

 

posted @ 2018-08-07 16:59  傻白甜++  阅读(4642)  评论(0编辑  收藏  举报
TOP