I am required to use nested for loops and print(\'*\', end=\' \') to create the pattern shown here:
And here is my code. I have figured out the first t
Pythonic way of doing this. Just 1 line of code (using list comprehension) for each pattern.
n = 10
# for A
print('\n'.join(['*'*i for i in range(1,n+1)]))
#output
*
**
***
****
*****
******
*******
********
*********
**********
# for B
print('\n'.join(['*'*i for i in range(n+1,0,-1)]))
#output
***********
**********
*********
********
*******
******
*****
****
***
**
*
# for C
print('\n'.join([' '*(n-i) + '*'*i for i in range(n,0,-1)]))
#output
**********
*********
********
*******
******
*****
****
***
**
*
# for D
print('\n'.join([' '*(n-i) + '*'*i for i in range(1,n+1)]))
#output
*
**
***
****
*****
******
*******
********
*********
**********