def player_choice():
marker = ' '
while marker not in ['X','O']:
marker = input('What do you want X or O? ')
if marker == 'X':
return ('X','O')
else:
return ('O','X')
I want to make it so that when the user inputs any integer the very first time it displays "Please select from X and O" and when the user enters the wrong value the second time it displays "Do you want to play the game seriously?", along with the loop.
CodePudding user response:
If I understand the question correctly, you would probably just need to add a counter and another test to your "if/else" block such as in the following code snippet.
def player_choice():
tries = 0
marker = ' '
while marker not in ['X','O']:
marker = input('What do you want X or O? ')
if marker == 'X':
return ('X','O')
elif marker == 'O':
return ('O','X')
else:
tries = 1
if tries > 1:
print("Please be serious")
tries = 0
choices = player_choice()
print("Choices are:", choices)
Testing that out, this is what I saw on my terminal.
@Una:~/Python_Programs/PlayerCoice$ python3 Choice.py
What do you want X or O? Q
What do you want X or O? Q
Please be serious
What do you want X or O? O
Choices are: ('O', 'X')
You can give that a try.