I have a simple try statement where i am assigning a variable to either x, o, or r (tic tac toe game i have made). The statements works if one of the three options is given, however, if it is something else given it says that it is returning a None object. I don't understand why it is not reassigning the variable to the new user input that is given on the second, third etc. run throughs
def chooseLetter(name):
try:
letter = input('Hello %s, would you like to be X or O or a random letter choice ("r") ' %name)
assert letter.lower() == 'x' or letter.lower()== 'o' or letter.lower() == 'r'
return letter
except AssertionError:
print('please choose either X or O ')
chooseLetter(name)
assertto check data.assertis meant to check your program's internal logic, i.e., if you get anAssertionErrorthat means there's something wrong with the code itself and it needs to be modified. For your caseValueErrorwould be more suitable.whileloop. For more on this topic, please see Asking the user for input until they give a valid response.