0
36views
Write a python program to print the series of 0 0 2 1 4 2 6 3 8 4
1 Answer
0
1views

Problem Statement:-

Series 0 0 2 1 4 2 6 3 8 4

Elements in the even index are the even multiples of 2 and elements in the odd index then divide the value by 2

Code:-

a=0
b=0
n=int(input("No of elements in the series:- "))
# iterate till the length of series
for i in range(n+1):
# to check if index is odd or even
    if i%2!=0:
#if even index then print even multiples of 
        if i>1:    
            a=a+2
            print(int(a),end=" ")
# if the index is odd multiple divide the value of odd multiple by 2 
    else:         
        b=a/2
        print(int(b),end=" ")

Output:-

enter image description here

Please log in to add an answer.