Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the same representation of the Tic-Tac-Toe game as seen in the previous question, complete the has_won() function which determines whether a player has won

image text in transcribed

Using the same representation of the Tic-Tac-Toe game as seen in the previous question, complete the has_won() function which determines whether a player has won a game. The function returns True if the player has won a game and False otherwise. This function takes two parameters: The parameter board which is a list of three strings representing the Tic-Tac-Toe board. The format is described in the previous question. The parameter player which represents the player that you want to check if they have won the game. This parameter will either be the string "0" or the string "X". A player wins Tic-Tac-Toe if they are able to fill a row or a column or a diagonal with their symbol. Some examples of the function being used are shown below. The print_board() function has been provided for you; you must not change its implementation For example: Test Result player1 = "0" 000 player2 = "X" #XX board = ["000","#XX", "X##"] X## print_board(board) Player has won: True print("Player", player1, "has won:", has_won(board, player1)) Player X has won: False print("Player", player2, "has won:", has_won (board, player2)) player1 = "0" O## player2 = "X" OXX board = ["@##", "XX", "OX#"] OX# print_board (board) Player has won: True print("Player", player1, "has won:", has_won (board, player1)) Player X has won: False print("Player", player2, "has won:", has_won (board, player2)) player1 = "0" O#X player2 = "X" X# board = ["0#X", "XO#", "XXO"] xxo print_board(board) Player has won: True print("Player", playeri, as won:", has_won (board, player1)) Player X has won: False print("Player", player2, "has won:", has_won (board, player2))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions