Advertisement
asweigart

diamond.py

Aug 2nd, 2022 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. """
  2. diamond.py
  3. This program prints repeating diamonds:
  4. O
  5. OOO
  6. OOOOO
  7. OOOOOOO
  8. OOOOOOOOO
  9. OOOOOOOOOOO
  10. OOOOOOOOO
  11. OOOOOOO
  12. OOOOO
  13. OOO
  14. O
  15. """
  16.  
  17. # Experiment with changing these CONSTANT variable values:
  18. SIZE = 15
  19. DIAMOND_CHAR = 'O'
  20.  
  21. while True:
  22. oCount = 1
  23. spaceCount = SIZE
  24.  
  25. # Print the top half of the diamond:
  26. while spaceCount > 0:
  27. print(' ' * spaceCount + DIAMOND_CHAR * oCount)
  28. oCount = oCount + 2
  29. spaceCount = spaceCount - 1
  30.  
  31. # Print the bottom half of the diamond:
  32. while oCount >= 1:
  33. print(' ' * spaceCount + DIAMOND_CHAR * oCount)
  34. oCount = oCount - 2
  35. spaceCount = spaceCount + 1
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement