热门
输入正整数n,求1到n的交错和:即-1+2-3+4-5+6+…+(-1)^n)*n
输入
2
输出
1
解释:-1+2=1
3
-2
解释:-1+2-3=-2
n = eval ( input ()) res =0 neg = True for i in range (1, n +1): if neg : neg = False res +=(- i ) elif not neg : neg = True res += i print ( res )