I have the following code printing an inverted pyramid using numbers from 0 to 9. However, I'm curious how can I change this code to print numbers in order starting from pyramid's end?
height = 5
num = 0
for i in reversed(range(1, height + 1)):
print(" " * (height - i), end="")
for j in range((i - 1) * 2 + 1):
print(num, end="")
if num == 9:
num = 0
else:
num += 1
print("\r")
The output of above code is:
012345678
9012345
67890
123
4
Desired output:
789012345
0123456
56789
234
1