Advertisement
acclivity

pyPythonsTriangle

Feb 14th, 2021
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # From the word "pythons", print a triangle like this:
  2.  
  3. # pythons
  4. #  ython
  5. #   tho
  6. #    h
  7.  
  8. s1 = "pythons"
  9. s1 += "*"               # add a string terminator to simplify the processing
  10. n = len(s1) >> 1        # compute how many lines we will print (half string length. Efficient bitwise divide-by-two)
  11. for x in range(n):
  12.     print(" " * x + s1[x:-x-1])     # First time round, it prints zero spaces followed by the complete original word
  13.                                     # 2nd time it prints 1 space followed by the word less 1 character off beginning and end
  14.                                     # etc.
  15.  
  16. # result
  17.  
  18. # pythons
  19. #  ython
  20. #   tho
  21. #    h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement