I have pattern which I am trying to print
Expected output :
1 * 2 * 3 * 4 * 5
1 * 2 * 3 * 4
1 * 2 * 3
1 * 2
1
I have written a code but not getting how to add this check so that last star should not be printed [ refer above expected output ]
n=5
l = [ str(i) + ' *' for i in range(1,n+1) ]
for j in range(1,n+1):
print(' '.join(l))
del l[-1]
My output :
1 * 2 * 3 * 4 * 5 *
1 * 2 * 3 * 4 *
1 * 2 * 3 *
1 * 2 *
1 *
>Solution :
Here’s what I got:
n=5
l = [ str(i) for i in range(1,n+1) ]
for _ in range(1,n+1):
print(' * '.join(l))
del l[-1:]
I essentially just removed the star in the list and used it as a separator.