Guest User

Untitled

a guest
May 21st, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. """Bonus exercise: extend the code to make the game board not square."""
  2.  
  3. def Board_dim():
  4. """Asks the user for board dimensions"""
  5. x = int(input('How many spaces wide should the board be?\n'))
  6. y = int(input('How high?\n'))
  7. return [x, y]
  8.  
  9. def Print_board(x, y):
  10. """Prints a game board of dimension x by y"""
  11. board = ['', '|', '']
  12. i = 1
  13. j = 1
  14. while i <= x:
  15. board[0] += ' ---'
  16. board[1] += ' |'
  17. board[2] += ' ---'
  18. i += 1
  19. while j < y:
  20. board.append(board[1])
  21. board.append(board[2])
  22. j += 1
  23. if x == 0 or y == 0:
  24. print(' ')
  25. else:
  26. for elem in board:
  27. print(elem)
  28.  
  29. if __name__=="__main__":
  30. [x, y] = Board_dim()
  31. Print_board(x, y)
Add Comment
Please, Sign In to add comment