Knowee
Questions
Features
Study Tools

Write a function called get_width(board) which accepts a list of strings representing a Connect Four board, and returns an integer representing the width of the board.For example:Test Resultboard = ['....', '....', '....', '....', '....']print(get_width(board))4board = ['......', '......', '......', '......', '......', '......', '......']print(get_width(board))6

Question

Write a function called get_width(board) which accepts a list of strings representing a Connect Four board, and returns an integer representing the width of the board.For example:Test Resultboard = ['....', '....', '....', '....', '....']print(get_width(board))4board = ['......', '......', '......', '......', '......', '......', '......']print(get_width(board))6

🧐 Not the exact question you are looking for?Go ask a question

Similar Questions

Write a function called create_board(width, height) which returns a list containing strings that represent the rows in a Connect Four board.The number of strings (i.e., the number of rows) is equal to the height, or a minimum of 4 if the value of height is less than 4, and a maximum of 10 if the value of height is greater than 10.The length of each string (i.e., the number of columns) is equal to the width, or a minimum of 4 if the value of width is less than 4, and a maximum of 10 if the value of width is greater than 10.Each string uses the "." character to represent each empty location.For example:Test Resultb = create_board(0, 0)print(b)['....', '....', '....', '....']b = create_board(6, 7)print(b)['......', '......', '......', '......', '......', '......', '......']

Write a function called display_board(board) which accepts a list of strings representing a Connect Four board. The function should print the board in the following format:The first string in the board list represents the bottom row of the board and subsequent strings represent higher rows, with the last string in the list representing the top row.Each row should be printed with a vertical bar "|" before the first column and after the last column, signifying the edges of the board.Each location in the board (initially represented by ".") is separated from adjacent locations by a space.No space is used between the location and the edge of the board.Below the contents of the board is a row of hyphen characters "-" signifying the bottom of the board. This row is surrounded by vertical bars "|"A single character corresponding to the label of each column appears below the corresponding column.  This row is surrounded by vertical bars "|"Each column is labelled with a single digit starting at 0 in the left column and increasing consecutively towards the right column.Notes:You can assume that the create_board(width, height) and get_width(board) functions are defined within CodeRunner for this question.  However, if you submit these yourself in the answer then the tests will still work correctly (if they meet the requirements specified in earlier questions).For example:Test Resultdisplay_board(['....', '....', '....', '....'])|. . . .||. . . .||. . . .||. . . .||-------||0 1 2 3|board = create_board(9, 7)display_board(board)|. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||. . . . . . . . .||-----------------||0 1 2 3 4 5 6 7 8|

def create_board(size): size = int(size) board = [[' '] * size for i in range(size)] return boarddef is_occupied(board, x, y): if x >= 0 and y >= 0 and board[x][y] != ' ': return True else: return False def place_on_board(board, stone, position): x = int(input('Please enter row line: ')) y = ord(input('Please enter column line: ')) if is_occupied(board, x, y): return False else: board[x][y] = stone return Trueboard = create_board(3)stone = "●"position = (1,2)place_on_board(board, stone, position)

Write a function called is_full(board) which accepts a board and returns True if the board is full (i.e., there are no empty spaces), and False otherwise.For example:Test Resultboard = ['....', '....', '....', '....']print(is_full(board))

def check_available_moves(board): available_moves = [] size = len(board) for row in range(size): # iterate go through rows for co in range(size): # iterate through column for each row if board[row][co] == ' ': #check the positoin is occupied or not available_moves.append(row, chr(co + 65)) return available_moves # return the available movesboard = create_board(9)print_board(board)check_available_moves(board)

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.