Home > Software design >  How to get the desired python pattern given below
How to get the desired python pattern given below

Time:04-04

How to get the below-desired output using python

12345

23451

34511

45111

51111

CodePudding user response:

This should work:

numbers = "12345"
for i in range(5):
    ones= ""
    for j in range(i):
        ones  = "1"
    out = numbers[i:]   ones
    print(out)

CodePudding user response:

Here's my try, I don't know if it will be easy to generalize this idea to do different patterns like this:

for i in range(1,6):
    for j in range(i,i 5):
        if j > 5:
            print(1,end = '')
        else:
            print(j,end = '')
    print('\n')
  • Related