How to print a pattern like this in python
Attachments:
Answers
Answered by
4
The given problem is solved using language - Python.
1. Using nested loops.
n=5
for i in range(n):
for j in range(i):
print('',end=' ')
for j in range(n-i):
print('*',end=' ')
print()
2. Using 1 loop.
n=5
for i in range(n):
print(i*' ',end='')
print((n-i)*'* ')
3. One liner.
print('\n'.join(' '*i+'* '*(5-i) for i in range(5)))
Note: Here I have taken n = 5 as there are 5 rows in this pattern. You can also take the value of n as input from the user.
* * * * *
* * * *
* * *
* *
*
See attachment for verification.
Attachments:
Similar questions
Math,
4 days ago
Social Sciences,
4 days ago
English,
4 days ago
English,
8 days ago
English,
8 months ago