sum=0flag=1for i in range(1,100): sum+=i*flag flag=-flagprint(sum)
最后那个-99应该是+99吧
total=0for i in range(1,100): #奇数加 if i%2!=0: total=total+i #偶数减 elif i%2==0: total=total-1print(a)
sum(( n*(-1,1)[n&1] for n in range(1,100) ))