Question: Functions can be used to replace multiple code statements. This occurs in the Tic - Tac - Toe game program within the tutorial 2 .
Functions can be used to replace multiple code statements. This occurs in the TicTacToe game program within the tutorial Finishing the TicTacToe Program; see the printBoard function created there as an example.
What if we wanted to replace the following lines in the TicTacToe game:
while row or row :
row intinputplayerTurn player, select a row :
if row or row :
printThe row must be between and
with a function called turn. For the call to this function, we could use:
row turnrow playerTurn
where we input into the function that we want to select a row row and which player is making this selection playerTurn
Which code segment properly implements this function?
def turncolrow, player:
goodselection True
while goodselection False:
colrowpicked intinputplayerTurn player, select a : formatcolrow
if colrowpicked or colrowpicked :
printThe must be between and formatcolrow
else:
goodselection True
return colrow
def turncolrow, player:
goodselection True
while goodselection False:
colrowpicked intinputplayerTurn player, select a : formatcolrow
if colrowpicked or colrowpicked :
printThe must be between and formatcolrow
else:
goodselection True
return colrowpicked
def turncolrow, player:
goodselection False
while goodselection False:
colrowpicked intinputplayerTurn player, select a : formatcolrow
if colrowpicked or colrowpicked :
printThe must be between and formatcolrow
else:
goodselection True
return colrow
def turncolrow, player:
goodselection False
while goodselection False:
colrowpicked intinputplayerTurn player, select a : formatcolrow
if colrowpicked or colrowpicked :
printThe must be between and formatcolrow
else:
goodselection True
return colrowpicked
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
