Write a Python program to print right triangle of 1 and 0 pattern using for loop.
rows = int(input("Enter Right Triangle of 1 & 0 Num Pattern Rows = ")) print("====Right Angled Triangle of 1 and 0 Numbers Pattern====") for i in range(1, rows + 1): for j in range(1, i + 1): if j % 2 == 0: print(0, end = ' ') else: print(1, end = ' ') print()
This Python example prints the right angled triangle with 1 and 0’s as alternative columns using a while loop.
rows = int(input("Enter Right Triangle of 1 & 0 Num Pattern Rows = ")) print("====Right Angled Triangle of 1 and 0 Numbers Pattern====") i = 1 while(i <= rows): j = 1 while(j <= i): if j % 2 == 0: print(0, end = ' ') else: print(1, end = ' ') j = j + 1 print() i = i + 1
Enter Right Triangle of 1 & 0 Num Pattern Rows = 12
====Right Angled Triangle of 1 and 0 Numbers Pattern====
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
1 0 1 0 1 0
1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0