Advertisement
asweigart

marquee.py

Aug 2nd, 2022 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. # marquee.py
  2.  
  3. # These are examples of the strings we want to produce with WIDTH = 10
  4. # and MESSAGE = 'Hello':
  5.  
  6. # First phase (showing the left part of the MESSAGE string):
  7. ' '
  8. ' H'
  9. ' He'
  10. ' Hel'
  11. ' Hell'
  12. ' Hello'
  13.  
  14. # Second phase (showing the full MESSAGE with decreasing indentation):
  15. ' Hello '
  16. ' Hello '
  17. ' Hello '
  18. ' Hello '
  19. 'Hello '
  20.  
  21. # Third phase (showin the right part of MESSAGE with zero indentation):
  22. 'ello '
  23. 'llo '
  24. 'lo '
  25. 'o '
  26. ' '
  27.  
  28.  
  29.  
  30. import time
  31.  
  32. # Experiment with changing these CONSTANT variable values:
  33. WIDTH = 30
  34. MESSAGE = 'Hello! How are you doing today?'
  35. DELAY = 0.1 # How many seconds to pause
  36.  
  37. while True:
  38. # First phase:
  39. leftChars = 0
  40. while leftChars <= len(MESSAGE):
  41. print('\n' * 30) # Print a bunch of newlines to "clear" the screen.
  42. print(' ' * (WIDTH - leftChars) + MESSAGE[0:leftChars])
  43. time.sleep(DELAY)
  44. leftChars = leftChars + 1
  45.  
  46. # Second phase:
  47. i = leftChars
  48. while WIDTH - i >= 0:
  49. print('\n' * 30)
  50. print(' ' * (WIDTH - i) + MESSAGE)
  51. time.sleep(DELAY)
  52. i = i + 1
  53.  
  54. # Third phase:
  55. i = 1
  56. while i < len(MESSAGE):
  57. print('\n' * 30)
  58. print(MESSAGE[i:len(MESSAGE)])
  59. time.sleep(DELAY)
  60. i = i + 1
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement