mardi 21 décembre 2021

How to print this pyramid pattern up side down?

I am trying to print below pyramid pattern. But not clicking how to build logic for it ?

Pattern :

5 4 3 2 1
  4 3 2 1
    3 2 1 
      2 1
        1 

I have tried this code seems like this is not a right approach to get it.Any solution is appreciated

import numpy as np
n = 5
cnt=0
var = np.arange(1,n+1)
for row in range(1,n+1):
  print(var[::-1][cnt:])
  cnt= cnt + 1

Output of above pattern:

[5 4 3 2 1]
[4 3 2 1]
[3 2 1]
[2 1]
[1]

Aucun commentaire:

Enregistrer un commentaire