Answer to Question #230030 in Python for Roti

Question #230030
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:32:20-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