Python Inverse Triangle Output Questions

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

It is a task to create a triangular program using overlapping for repetitive statements, and the output form is

12345
 2345
  345
   45
    5

I have to do this, but I can't figure it out. How should I don't know what to do I don't know how to program the number and the form that comes out like that (blank in front) because there are a lot of things that are expressed as *.

python

2022-09-20 10:28

1 Answers

for l in '''12345
 2345
  345
   45
    5'''.split("\n"):
    print(l)
s = list("12345")
for i in range(5):
    print(''.join(s))
    s[i] = ' '
for i in range(1,6):
    s = ''.join(str(j) for j in range(i, 6))
    print(f"{s:>5}")


2022-09-20 10:28

If you have any answers or tips


© 2022 pinfo. All rights reserved.