Python Code Example: triangle pattern

This program outputs a triangle pattern.

rows = 8

for i in range(0, rows + 1):
    for j in range(1, i):
        print(j, end=" ")
    print()

for i in range(rows + 1, 0, -1):
    for j in range(1, i):
        print(j, end=" ")
    print()
Output
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1