Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- diamond2.py
- This program prints a centered row of Os of varying sizes:
- O
- O
- OOO
- OOOOO
- OOOOOOO
- OOOOOOOOO
- OOOOOOO
- OOOOOOOOO
- OOOOOOO
- OOOOO
- OOOOOOO
- OOOOOOOOO
- OOOOOOOOO
- OOOOOOO
- OOOOO
- OOOOOOO
- OOOOO
- OOOOOOO
- OOOOO
- OOOOOOO
- OOOOO
- """
- import random, time
- # Experiment with changing these CONSTANT variable values:
- MAX_SIZE = 10
- DIAMOND_CHAR = 'O'
- oCount = 1
- while True:
- if random.randint(0, 1) == 0:
- # Increase the size of the diamond
- if oCount <= MAX_SIZE - 2: # Only increase if it won't increase beyond MAX_SIZE.
- oCount = oCount + 2
- else:
- # Decrease the size of the diamond
- if oCount >= 3: # Only decrease if it won't decrease to less than 1.
- oCount = oCount - 2
- spaceCount = (MAX_SIZE - oCount) // 2
- print(' ' * spaceCount + DIAMOND_CHAR * oCount)
- time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement