Answer to Question #230051 in Python for Aditi

Question #230051

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-27T02:04:30-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS