Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # marquee.py
- # These are examples of the strings we want to produce with WIDTH = 10
- # and MESSAGE = 'Hello':
- # First phase (showing the left part of the MESSAGE string):
- ' '
- ' H'
- ' He'
- ' Hel'
- ' Hell'
- ' Hello'
- # Second phase (showing the full MESSAGE with decreasing indentation):
- ' Hello '
- ' Hello '
- ' Hello '
- ' Hello '
- 'Hello '
- # Third phase (showin the right part of MESSAGE with zero indentation):
- 'ello '
- 'llo '
- 'lo '
- 'o '
- ' '
- import time
- # Experiment with changing these CONSTANT variable values:
- WIDTH = 30
- MESSAGE = 'Hello! How are you doing today?'
- DELAY = 0.1 # How many seconds to pause
- while True:
- # First phase:
- leftChars = 0
- while leftChars <= len(MESSAGE):
- print('\n' * 30) # Print a bunch of newlines to "clear" the screen.
- print(' ' * (WIDTH - leftChars) + MESSAGE[0:leftChars])
- time.sleep(DELAY)
- leftChars = leftChars + 1
- # Second phase:
- i = leftChars
- while WIDTH - i >= 0:
- print('\n' * 30)
- print(' ' * (WIDTH - i) + MESSAGE)
- time.sleep(DELAY)
- i = i + 1
- # Third phase:
- i = 1
- while i < len(MESSAGE):
- print('\n' * 30)
- print(MESSAGE[i:len(MESSAGE)])
- time.sleep(DELAY)
- i = i + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement