题解 | #牛牛学数列#
牛牛学数列
http://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
找一下规律,奇数加,偶数减, for遍历一下判断下奇偶累加就好了!
a=int(input())
b=0
for x in range(1,a+1):
if x%2 != 0:
b+=x
else:
b-=x
print(b)
牛牛学数列
http://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
找一下规律,奇数加,偶数减, for遍历一下判断下奇偶累加就好了!
a=int(input())
b=0
for x in range(1,a+1):
if x%2 != 0:
b+=x
else:
b-=x
print(b)
相关推荐