Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Functions can be used to replace multiple code statements that perform essentially the same task with different values. This occurs in the Tic - Tac

Functions can be used to replace multiple code statements that perform essentially the same task with different values. This occurs in the Tic-Tac-Toe game program within the tutorial. See the printBoard function created there as an example. What other code within the Tic-Tac-Toe program would be a good set of statements to turn into a function?
a.)
Changing validMove from False to True:
validMove=True;
b.)
Decrementing the column and row:
col -=1
row -=1
c.)
Players selecting a column and row:
while (col <1 or col >3):
col = int(input(playerTurn +" player, select a column 1-3: "))
if (col <1 or col >3):
print("The column must be between 1 and 3.")
while (row <1 or row >3):
row = int(input(playerTurn +" player, select a row 1-3: "))
if (row <1 o)r row >3):
print("The row must be between 1 and 3.")
d.)
Changing playerTurn from X to O:
if playerTurn =="X":
playerTurn="O"
else:
playerTurn="X"

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

What is meant by planning or define planning?

Answered: 1 week ago

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago