I have a problem regarding recursive functions in Python 3. Consider the below code snippets:
Code snippet A
def select():
player = input('Player 1: Do you want to be X or O? ')
if player != 'X' and player != 'O':
player = select()
return player
Code snippet B
def select():
player = input('Player 1: Do you want to be X or O? ')
if player != 'X' and player != 'O':
player = select()
return player
While I somewhat understand the difference (Code A returns a 'None' Type while Code B returns an X or an O) why is that the case? For Code A, before it is returned, player is again reassigned to the select function, which prompts an input until an 'X' or 'O' is provided. Meaning, the return function should never execute as the select() function is recursively called until an X or an O is supplied.
Can you explain to me why snippet A is wrong and returns a None type? Thanks