Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Bonus exercise: extend the code to make the game board not square."""
- def Board_dim():
- """Asks the user for board dimensions"""
- x = int(input('How many spaces wide should the board be?\n'))
- y = int(input('How high?\n'))
- return [x, y]
- def Print_board(x, y):
- """Prints a game board of dimension x by y"""
- board = ['', '|', '']
- i = 1
- j = 1
- while i <= x:
- board[0] += ' ---'
- board[1] += ' |'
- board[2] += ' ---'
- i += 1
- while j < y:
- board.append(board[1])
- board.append(board[2])
- j += 1
- if x == 0 or y == 0:
- print(' ')
- else:
- for elem in board:
- print(elem)
- if __name__=="__main__":
- [x, y] = Board_dim()
- Print_board(x, y)
Add Comment
Please, Sign In to add comment