Write a Python program to print right pascals triangle of mirrored numbers pattern using for loop.
rows = int(input("Enter Right Pascals Mirrored Numbers Rows = ")) print("====Right Pascals Mirrored Numbers Triangle Pattern====") for i in range(rows, 0, -1): for j in range(i, rows + 1): print(j, end = ' ') for k in range(rows - 1, i - 1, -1): print(k, end = ' ') print() for i in range(2, rows + 1): for j in range(i, rows + 1): print(j, end = ' ') for k in range(rows - 1, i - 1, -1): print(k, end = ' ') print()
This Python program prints the right pascals triangle pattern of mirrored numbers using a while loop.
rows = int(input("Enter Right Pascals Mirrored Numbers Rows = ")) print("====Right Pascals Mirrored Numbers Triangle Pattern====") i = rows while(i >= 1): j = i while(j <= rows): print(j, end = ' ') j = j + 1 k = rows - 1 while(k >= i): print(k, end = ' ') k = k - 1 print() i = i - 1 i = 2 while(i <= rows): j = i while(j <= rows): print(j, end = ' ') j = j + 1 k = rows - 1 while(k >= i): print(k, end = ' ') k = k - 1 print() i = i + 1
Enter Right Pascals Mirrored Numbers Rows = 12
====Right Pascals Mirrored Numbers Triangle Pattern====
12
11 12 11
10 11 12 11 10
9 10 11 12 11 10 9
8 9 10 11 12 11 10 9 8
7 8 9 10 11 12 11 10 9 8 7
6 7 8 9 10 11 12 11 10 9 8 7 6
5 6 7 8 9 10 11 12 11 10 9 8 7 6 5
4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4
3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3
2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2
3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3
4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4
5 6 7 8 9 10 11 12 11 10 9 8 7 6 5
6 7 8 9 10 11 12 11 10 9 8 7 6
7 8 9 10 11 12 11 10 9 8 7
8 9 10 11 12 11 10 9 8
9 10 11 12 11 10 9
10 11 12 11 10
11 12 11
12
In this Python pattern example, we used the forloopIter function to display the right pascals mirrored numbers triangle.
def forloopIter(rows): for j in range(i, rows + 1): print(j, end = ' ') for k in range(rows - 1, i - 1, -1): print(k, end = ' ') rows = int(input("Enter Right Pascals Mirrored Numbers Rows = ")) print("====Right Pascals Mirrored Numbers Triangle Pattern====") for i in range(rows, 0, -1): forloopIter(rows) print() for i in range(2, rows + 1): forloopIter(rows) print()
Enter Right Pascals Mirrored Numbers Rows = 15
====Right Pascals Mirrored Numbers Triangle Pattern====
15
14 15 14
13 14 15 14 13
12 13 14 15 14 13 12
11 12 13 14 15 14 13 12 11
10 11 12 13 14 15 14 13 12 11 10
9 10 11 12 13 14 15 14 13 12 11 10 9
8 9 10 11 12 13 14 15 14 13 12 11 10 9 8
7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7
6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6
5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5
4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4
3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3
2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2
3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3
4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4
5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5
6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6
7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7
8 9 10 11 12 13 14 15 14 13 12 11 10 9 8
9 10 11 12 13 14 15 14 13 12 11 10 9
10 11 12 13 14 15 14 13 12 11 10
11 12 13 14 15 14 13 12 11
12 13 14 15 14 13 12
13 14 15 14 13
14 15 14
15