Computer Science
Write programs to print the following shapes:
*
* *
* * *
* *
*
Python
Python Control Flow
16 Likes
Answer
n = 3 # number of rows
# upper half
for i in range(n) :
for j in range(n, i+1, -1) :
print(' ', end = '')
for k in range(i+1) :
print('*', end = ' ')
print()
# lower half
for i in range(n-1) :
for j in range(i + 1) :
print(' ', end = '')
for k in range(n-1, i, -1) :
print('*', end = ' ')
print()
Output
*
* *
* * *
* *
*
Answered By
9 Likes
Related Questions
Write programs to find the sum of the following series:
x + x2/2 + x3/3 + …… + xn/n (Input x and n both)
Write programs to find the sum of the following series:
x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6! (Input x)
Write programs to print the following shapes:
*
* *
* * *
* *
*Write programs to print the following shapes:
*
* *
* *
* *
*