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

 

Python Practice Problems For Beginners-

Problem Statement:-Write a python program to print the series of 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 

0        0        2        1        4       2      6        3         8       4
[0]    [1]    [2]      [3]     [4]    [5]    [6]     [7]      [8]     [9]

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))
# if the index is odd multiple divide the value of odd multiple by 2 
    else:         
        b=a/2
        print(int(b))

Output:-



Post a Comment

0 Comments