Advertisement
CodingComputing

Crown Pattern

Apr 2nd, 2024 (edited)
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. # *Crown Pattern* solution by @CodingComputing
  2.  
  3. height = 7
  4. width = 2*height-1
  5. for row_num in range(1, height+1):
  6.     if row_num <= height//2:  # The "spikey" part of the crown
  7.         edge_stars_num = row_num
  8.         center_stars_num = 2*row_num - 1
  9.         total_stars_num = 2*edge_stars_num + center_stars_num
  10.         interim_spaces_num = (width - total_stars_num) // 2
  11.         print(
  12.             '*'*edge_stars_num      +  " "*interim_spaces_num +
  13.             '*'*center_stars_num    +
  14.             " "*interim_spaces_num  +  '*'*edge_stars_num
  15.         )
  16.     else:  # The "base" part of the crown
  17.         print('*' * width)
  18.  
  19. # Output:
  20. #
  21. # *     *     *
  22. # **   ***   **
  23. # *** ***** ***
  24. # *************
  25. # *************
  26. # *************
  27. # *************
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement