NESTED LOOPS
Listing 2.3 shows the content of Triangular1.py that illustrates how to print a row of consecutive integers (starting from 1), where the length of each row is one greater than the previous row.
Listing 2.3: Triangular1.py
max = 8
for x in range(1,max+1):
for y in range(1,x+1):
print(y, '', end='')
print()
Listing 2.3 initializes the variable max with the value 8, followed by an outer for loop whose loop variable x ranges from 1 to max+1. The inner loop has a loop variable y that ranges from 1 to x+1, and the inner loop prints the value of y. The output of Listing 2.3 is as follows:
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