This may seem like a silly question, but I've actually stumped myself. I was trying to write a "pyramid" pattern code, and I succeeded, but I have no idea how I did it. The first half of the pyramid was obvious, the second half I did by mistake, and I can't figure out why the code actually works.
Here is my code:
for x in range(5): # I understand why this loop works, its fairly simple
for y in range(x+1):
print(y, end='')
print('')
for x in range(5):
for y in range(y): # This is the part I can't seem to wrap my head around
print(y, end='')
print('')
The output is:
0
01
012
0123
01234
0123
012
01
0
I've been staring at it and I can't understand how for y in range(y) actually works.