* * * * * * * * * * * * * * *
Code
row=5
for i in range(row,0,-1):
for j in range(i):
print("*",end=" ")
print()
Generally,
- There two loops Inner loop and Outer loop.
- Outer loop for row.
- Inner loop for column.
Explanation:
-
row=5as we need five rows you can have more than that. -
for i in range(row,0,-1):it will print row in reverse order-1represent it, if you will not write-1it will print nothing. And as you knowrange(5,0,-1)doesn't print last number like 5,4,3,2,1. -
for j in range(i):for every row there column is printed. Example,
11 12 13 14 15
21 22 23 24 25
Dry Run Table:
i -> Range(row,0,-1) -> range(5,0,-1)
j -> Range(i)
| i | j | Output |
|---|---|---|
| 5 | 0 1 2 3 4 | ***** |
| 4 | 0 1 2 3 | **** |
| 3 | 0 1 2 | *** |
| 2 | 0 1 | ** |
| 1 | 0 | * |
Top comments (0)