Write a Python program to find sum of Series 2+4+6+8

 Python program to find sum of Series 2+4+6+8

Series:- 0+2+4+6+8......+n
Maximum range is the last element in the series.
for eg:- 0+2+4+6+8
max element is 8

Code:-


n=int(input("Maximum range:- "))
sum=0
#iterate the loop until 
for i in range (n+1):
#if loop to check if the the no is even
  if i%2==0:
#if the no is even then add the value to the sum
    sum=sum+i
#print statement to print the even no and sum of elements till that even no
    print("Even No",i,"Sum of series of no's",sum)


Output:-

Maximum range:- 8 Even No 0 Sum of series of no's 0 Even No 2 Sum of series of no's 2 Even No 4 Sum of series of no's 6 Even No 6 Sum of series of no's 12 Even No 8 Sum of series of no's 20


Series:- 2+4+6+8......+n

Code:-

n=int(input("Maximum range:- "))
sum=0
#iterate the loop until 
for i in range (2,n+1):
#if loop to check if the the no is even
  if i%2==0:
#if the no is even then add the value to the sum
    sum=sum+i
#print statement to print the even no and sum of elements till that even no
    print("Even No",i,"Sum of series of no's",sum)

Output:-

Maximum range:- 8 Even No 2 Sum of series of no's 2 Even No 4 Sum of series of no's 6 Even No 6 Sum of series of no's 12 Even No 8 Sum of series of no's 20

Post a Comment

0 Comments