Advertisement
Programmin-in-Python

Printing the famously decorated string

Feb 17th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. def decorator(str1):
  2.     strlen = len(str1)
  3.     mid = len(str1)//2
  4.  
  5.     for i in range(mid):
  6.         print((" "*i)+f"{str1[i]}"+(" "*len(str1[i+1:strlen-1-i]))+f"{str1[strlen-1-i]}")
  7.  
  8.     if strlen%2 != 0:
  9.         print((" "*(i+1))+str1[mid])
  10.  
  11. decorator("python")
  12.  
  13. '''
  14. Output:-
  15.  
  16. p    n
  17. y  o
  18.  th
  19. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement