this code should be in python:                                                                                                                                  First, it is randomly determined if the user starts the game or the computer and this information is shown to the user. The player who starts always starts as “X”.                                                                                                    •The players (computer and the user) will then take turns in playing. The computer will choose a random empty spot on its turn. The user enters its choice in the console. • Each of the empty spots have a corresponding number that the players choose on their turn. If the user enters anything other than the number of an empty spot (not yet filled with “X” or “O”), it will not be accepted, and they will be prompted to enter a correct number.                                                                                                                                                                      After each turn, two things need to be done: 1) displaying the updated board 2) checking if anyone has won (it should be printed who has won – the user or the computer). • The game goes on until someone wins or until all the 9 empty spots are filled and no one has won. When the game ends, the user should see the message saying who has won (even if no one). You should implement at least the two following functions : DisplayBoard(board) Parameter board is a dictionary containing the non-empty spots of the board. This function does not return anything. It will just print the content of the board as depicted in Gameplay example.                                                                                              HasWon(board) Parameter board is a dictionary containing the non-empty spots of the board. This function determines if anyone has won and returns a suitable value (up to you how you want to handle the returned value).  Creating other functions can be helpful (such as checking if the user input is valid, the general gameplay, etc.). The design and implementation of other functions is up to you.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

this code should be in python:                                                                                                                                  First, it is randomly determined if the user starts the game or the computer and this information is shown to the user. The player who starts always starts as “X”.                                                                                                    •The players (computer and the user) will then take turns in playing. The computer will
choose a random empty spot on its turn. The user enters its choice in the console.
• Each of the empty spots have a corresponding number that the players choose on their
turn. If the user enters anything other than the number of an empty spot (not yet filled
with “X” or “O”), it will not be accepted, and they will be prompted to enter a correct
number.                                                                                                                                                                      After each turn, two things need to be done: 1) displaying the updated board 2) checking
if anyone has won (it should be printed who has won – the user or the computer).
• The game goes on until someone wins or until all the 9 empty spots are filled and no one
has won. When the game ends, the user should see the message saying who has won
(even if no one).

You should implement at least the two following functions :

DisplayBoard(board)
Parameter board is a dictionary containing the non-empty spots of the board.
This function does not return anything. It will just print the content of the
board as depicted in Gameplay example.                                                                                             

HasWon(board)
Parameter board is a dictionary containing the non-empty spots of the board.
This function determines if anyone has won and returns a suitable value (up to
you how you want to handle the returned value). 

Creating other functions can be helpful (such as checking if the user input is valid, the general
gameplay, etc.). The design and implementation of other functions is up to you.

 

 

 

3
4
5
7
8
1.
Transcribed Image Text:3 4 5 7 8 1.
Gameplay example
Game is startin.
You will start the game. Please enter your choice:
4
Updated board:
_X_
Computer is playing.
Updated board:
LI_0_
|_x_I.
Transcribed Image Text:Gameplay example Game is startin. You will start the game. Please enter your choice: 4 Updated board: _X_ Computer is playing. Updated board: LI_0_ |_x_I.
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education