Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # From the word "pythons", print a triangle like this:
- # pythons
- # ython
- # tho
- # h
- s1 = "pythons"
- s1 += "*" # add a string terminator to simplify the processing
- n = len(s1) >> 1 # compute how many lines we will print (half string length. Efficient bitwise divide-by-two)
- for x in range(n):
- print(" " * x + s1[x:-x-1]) # First time round, it prints zero spaces followed by the complete original word
- # 2nd time it prints 1 space followed by the word less 1 character off beginning and end
- # etc.
- # result
- # pythons
- # ython
- # tho
- # h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement