Write a code to find out the sum of the sequence 2 -4 6 -8 10 -12.... while the last value will be determined from input. Use a loop to solve the problem.
n = int(input())
m = 1
total = 0
while True:
total += 2 * m * (-1) ** (m - 1)
if 2 * m * (-1) ** (m - 1) == n:
break
m += 1
print(total)
Comments
Leave a comment