I'm trying to complete a python Hangman miniproject to help me learn to code.
I've created a function that will hopefully ask the player for a letter, check the letter is only 1 letter and make sure it is not a number.
Here is the code I have so far:
def getLetter():
letter = raw_input('Please enter a letter...')
if letter.isdigit() == True:
print('That is a number!')
getLetter()
if len(str(letter)) >1:
print("Sorry, you have to enter exactly ONE letter")
getLetter()
else:
return letter
This works fine when the first input is correct, ie. one letter. However, when the input is incorrect, e.g 'ddddd', the program asks for another letter to be input but will either return the initial input ('ddddd') rather than the new input, or return nothing at all.
How can I make it return the new input? Do I need to clear the raw_input? If so, how?