Programmin-in-Python

Printing a Highly Satisfying Pattern

Oct 24th, 2021 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. n = int(input("Enter the value of N : "))
  2. string = f"{n}" * (n*2-1)
  3. res = [string]
  4.  
  5. # Decreasing Pattern (First Half)
  6. i = 1
  7. n -= 1
  8. while n>0:
  9.     str_temp = f"{n}"*len(string[i:len(string)-i])
  10.     string = string[:i] + str_temp + string[::-1][:i][::-1]
  11.     res.append(string)
  12.  
  13.     n -= 1
  14.     i += 1
  15.  
  16. # Increasing Pattern (Second Half)
  17. res.extend(res[::-1][1:])
  18.  
  19. # Displaying the Pattern
  20. for i in res:
  21.     print(" ".join(tuple(i)))
Add Comment
Please, Sign In to add comment