So, this functions is supposed to get a guess from a user. This guess should be one character and does not have any whitespaces in it.
The problem is, when I enter one space ' ' it returns 'You must enter a guess'. However, when I enter 2 spaces ' ' it returns 'You can only guess a single character'.
I need it to display 'You must enter a guess' instead. Whether the input contained one space or two or tap or two or even mix with tap and spaces. How can I do that?
def get_guess(repeated_guess):
while True:
guess = input('Please enter your next guess: ') # ask for input
guess.strip() # remove all spaces
guess = str(guess).lower() # convert it to lowercase string
if len(guess) > 1: # check if it's more than one character
print('You can only guess a single character.')
elif guess.isspace(' '):
print('You must enter a guess.')
elif guess in repeated_guess: # check if it's repeated
print('You already guessed the character:', guess)
else:
return guess