Q. Print the following pattern in Python.
*
**
***
****
*****
Code:
n=5
for i in range(1, n+1):
for j in range(1, i+1):
print("*", end=" ")
print()
Program Components Table:
Component Name/Code Type Description
Integer Holds the number of rows for
Variable n
Variable the pattern (5 in this case).
Iterates from 1 to n for each
Variable i Loop Variable
row.
Iterates from 1 to i to print
Variable j Loop Variable
stars in each row.
Built-in Generates a sequence of
Function range()
Function numbers used in the for loops.
Prints the output. In inner loop:
Built-in
Function print() prints *, in outer loop: prints
Function
newline.
Prevents the print() function
Print
Parameter end=" " from moving to a new line after
Parameter
each star.
for i in
Loop Outer Loop Controls the number of rows.
range(...)