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("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)
Comments
Leave a comment