w it works: • 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.

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:

you will be implementing a simple Tic-Tac-Toe game without the graphics.
Here is how it works:

• 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.

Game is starting.
You will start the game. Please enter your choice:
4
Updated board:
_x_],
Computer is playing.
Updated board:
|_0_
_x_|
Transcribed Image Text:Game is starting. You will start the game. Please enter your choice: 4 Updated board: _x_], Computer is playing. Updated board: |_0_ _x_|
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 8 images

Blurred answer
Knowledge Booster
Array
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
  • SEE MORE 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