In this shot, we will discuss how to generate a rectangle pattern using numbers in Python.
Numerous patterns can be printed using Python once we have a strong grasp on concepts involving loops. Here, we will be using simple for
loops to generate a rectangle pattern using numbers.
To execute a rectangular pattern using Python programming, we will be using two for
loops, one outer and one nested loop:
Let’s look at the below code snippet.
# Initialising Length and Breadth rows = 3 columns = 6 # Loop through number of rows for i in range(rows): # Loop through number of columns for j in range(columns): # Printing Pattern print(i+1, end = ' ') print()
for
loop to iterate through the number of rows.for
loop to iterate through the number of columns.i+1
has been used so as to start the pattern from 1. i
increases with the increase in row number.RELATED TAGS
CONTRIBUTOR
View all Courses