In this shot, we will discuss how to generate a rectangle pattern using stars in Python.
Numerous patterns can be printed using python, once we have a strong grip over the concepts involving loops. Here we will be using simple for
loops to generate a rectangle pattern using stars.
To execute a rectangular pattern using Python programming, we will use 2 for
loops:
Let’s look at the code snippet below.
# 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('*', end = ' ') print()
for
loop to iterate through the number of rows.for
loop to iterate through the number of columns.print()
statement is used to move to the next line.RELATED TAGS
CONTRIBUTOR
View all Courses