This Python program uses nested loops to generate an 8×8 number table.
In each row, the first few values increase from 2 up to the row index + 1.
The remaining cells are filled with the number 1.
# Number of rows and columns
n = 8
# Generate table using nested loops
for i in range(1, n + 1):
for j in range(1, n + 1):
if j <= i:
print(j + 1, end=" ")
else:
print(1, end=" ")
print()
2 1 1 1 1 1 1 1
2 2 1 1 1 1 1 1
2 2 3 1 1 1 1 1
2 2 3 4 1 1 1 1
2 2 3 4 5 1 1 1
2 2 3 4 5 6 1 1
2 2 3 4 5 6 7 1
2 2 3 4 5 6 7 8
- The outer loop controls the rows (1 to 8)
- The inner loop controls the columns (1 to 8)
- If the column index is less than or equal to the row index, print j + 1
- Otherwise, print 1
- end=" " keeps the output on the same line
- print()