Computer Science
Write programs to print the following shapes:
*
* *
* * *
* *
*
Python
Python Control Flow
9 Likes
Answer
n = 3 # number of rows
# upper half
for i in range(n) :
for k in range(i+1) :
print('*', end = ' ')
print()
# lower half
for i in range(n-1) :
for k in range(n-1, i, -1) :
print('*', end = ' ')
print()
Output
*
* *
* * *
* *
*
Answered By
4 Likes