找一下规律,奇数加,偶数减, for遍历一下判断下奇偶累加就好了!
a=int(input())
b=0
for x in range(1,a+1):
if x%2 != 0:
b+=x
else:
b-=x
print(b)
找一下规律,奇数加,偶数减, for遍历一下判断下奇偶累加就好了!
a=int(input())
b=0
for x in range(1,a+1):
if x%2 != 0:
b+=x
else:
b-=x
print(b)