Part of the series

Several example codes

~2 min read • Updated Oct 3, 2025

Program Overview

This Python program uses nested loops to generate three types of output:
1. A single row of repeated 8s
2. A row containing the numbers 1 and 2
3. A 9×8 table where each row starts with an increasing number and continues sequentially for 8 columns


Python Code:


# Part 1: Print eight 8s in a row
for i in range(8):
    print(8, end=" ")
print()  # New line

# Part 2: Print numbers 1 and 2
for i in range(1, 3):
    print(i, end=" ")
print("\n")  # New line and spacing

# Part 3: Structured table with increasing sequences
for row in range(1, 10):
    for col in range(8):
        print(row + col, end=" ")
    print()

Sample Output:


8 8 8 8 8 8 8 8  
1 2  

1 2 3 4 5 6 7 8  
2 3 4 5 6 7 8 9  
3 4 5 6 7 8 9 10  
4 5 6 7 8 9 10 11  
5 6 7 8 9 10 11 12  
6 7 8 9 10 11 12 13  
7 8 9 10 11 12 13 14  
8 9 10 11 12 13 14 15  
9 10 11 12 13 14 15 16

Step-by-Step Explanation:

- Part 1 uses a simple loop to print the number 8 eight times
- Part 2 prints numbers 1 and 2 using a loop from 1 to 2
- Part 3 uses nested loops:
— The outer loop controls the rows (1 to 9)
— The inner loop adds the column index to the row index to generate each cell
- end=" " keeps numbers on the same line
- print() moves to the next line after each row


Written & researched by Dr. Shahin Siami