Advertisement
Programmin-in-Python

Iterating within one list alone and printing a descendin pattern

Jan 22nd, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. n = int(input("Enter the Starting Row of Numbers : "))
  2. str1, L1 = "", [1, 2, 3, 4, 5, 6, 7, 8, 9]
  3. j, start = 0, 0
  4.  
  5. for i in L1:
  6.     str1 += str(i)
  7.    
  8. while n >= 1:
  9.     end = start+n
  10.  
  11.     if end > len(str1):
  12.         req_str = str1[start:]
  13.         new_n = n-len(req_str)
  14.         new_start = 0
  15.         req_str += str1[new_start:new_start+new_n]
  16.  
  17.     else:      
  18.         req_str = str1[start:end]
  19.  
  20.     print(req_str)
  21.    
  22.     j += 1
  23.     n -= 1
  24.     start = str1.index(req_str[-1]) + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement