0
498views
Write a Python Program to Create Pyramid No Pattern of 0's and 1's in Python (0 if row no is even & 1 if row no is odd)
1 Answer
0
4views

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("No of Rows in the pattern: "))
for i in range(n+1):
    for j in range(i):
        if(i%2==0):
            print(0,end=" ")
        else:
            print(1,end=" ")
    print()

Output:-

enter image description here

Please log in to add an answer.