KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Write Python code to display the following pattern:

1
3 5
5 7 9
7 9 11 13
9 11 13 15 17

Python Control Flow

2 Likes

Answer

for i in range(1, 6):
    
    n = 2 * i - 1
    
    for j in range(1, i + 1):
        print(n, end=" ")
        n = n + 2
    
    print()

Output

1 
3 5 
5 7 9 
7 9 11 13 
9 11 13 15 17 

Answered By

1 Like


Related Questions