Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!