Answer to Question #232797 in Python for Sajib

Question #232797

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-09-03T01:41:22-0400
N = int(input("Enter the number of elements in series: "))
Sum = 0
s=""
for r in range(0,N):
    u = (2*r+2)*((-1)**r)
    if(u>0): s=s+"+"+str(u)
    else:    s = s+str(u)
    Sum = Sum + u




print("Sum of series: ",s," = ",Sum)

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