rows = 5
for i in range(1, rows + 1):
up = "".join(str(k) for k in range(1, i + 1))
down = up[-2::-1] # the same digits backwards, without the middle one
print(" " * (rows - i) + up + down)
Output Verified by running it on Python 3
1
121
12321
1234321
123454321
Each row is leading spaces, the rising digits, and the rising digits reversed minus the last one (up[-2::-1]).
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!