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.
1
Expert's answer
2021-08-26T18:52:36-0400
n = int(input())
m = 1total = 0while True:
total += 2 * m * (-1) ** (m - 1)
if2 * m * (-1) ** (m - 1) == n:
breakm += 1print(total)
Comments