vendredi 31 décembre 2021

not able to define logic for decrementing pattern

I am trying to print the below pattern but not getting how to build logic where i am going wrong in below code. I want to achieve using stack

Expected output :

01
02 01
03 02 01
04 03 02 01
05 04 03 02 01
06 05 04 03 02 01
07 06 05 04 03 02 01
08 07 06 05 04 03 02 01
07 06 05 04 03 02 01
06 05 04 03 02 01
05 04 03 02 01
04 03 02 01
03 02 01
02 01
01

My code :

n=15
lst=[]
var=''
lg = len(str(n))

  for row in range(1,n+1):
    if row <=breaking:
      print(  str(row).zfill(lg) + ' ' +var )
      var = str(row).zfill(lg) + ' ' +var 
    else:
      pass

This above code printed up till here after that how to procced with decrementing pattern

01
02 01
03 02 01
04 03 02 01
05 04 03 02 01
06 05 04 03 02 01
07 06 05 04 03 02 01
08 07 06 05 04 03 02 01

Aucun commentaire:

Enregistrer un commentaire