Python program to print even odd number pyramid

Sure, here's a Python program that prints an even-odd number pyramid: 

 

n = int(input("Enter the number of rows: "))

for i in range(1, n+1):
    for j in range(1, i+1):
        if (i+j) % 2 == 0:
            print("1", end=" ")
        else:
            print("0", end=" ")
    print()

In this program, the user is prompted to enter the number of rows they want in the pyramid. The outer for loop iterates through each row, and the inner for loop iterates through each column in that row. The condition (i+j) % 2 == 0 checks whether the sum of the row and column indices is even, in which case the program prints a 1, and otherwise it prints a 0.

Here's an example output of the program when the user enters 5 as the number of rows: 

 

Enter the number of rows: 5
1 
0 1 
1 0 1 
0 1 0 1 
1 0 1 0 1 

As you can see, the program prints a pyramid of alternating 0s and 1s, with each row having one more number than the previous row. The program can be modified to print a pyramid of any other alternating pattern simply by changing the values in the if-else statement inside the inner for loop.

Submit Your Programming Assignment Details