#2 Pyramid No Pattern of 0's and 1's in Python (0 if row no is even & 1 if row no is odd)

 

Pyramid No Pattern of of 0's and 1's in Python 


Explanation:-

Step 1:- Take input for no of rows

Step 2:- Start 1st for loop to iterate n no of times (n rows)

Step 3:- Take 2nd for loop to iterate i items in a row

Step 4:- Increment the value of i from 1 to n

Step 5:- Stop 

Hint:-

Here we have to print 1 if row no is odd and 0 if row no is even
so for row no check the value of i if even print 0 else print 1


Code:-

#even_row 0 & odd_row 1
n=int(input())
for i in range(n+1):
    for j in range(i):
        if(i%2==0):
            print(0,end=" ")
        else:
            print(1,end=" ")
    print()


Run The Code


Any Doubts please put a comment ...


Post a Comment

0 Comments