-3

Python function using input() returns empty string if the right answer is not provided on first try

possible_options = ['R', 'P', 'S']

print('''
    Welcome to the rock, paper, scissors game.
    Please choose either rock (r), paper (p)
    or scissors (s) to start playing.        
''')

def human():
    human_choice: str = input('''
        Write your choice here >>>: 
    ''').upper()

    if human_choice not in possible_options:
        print('''
        Come on, you\'re smarter than that.
        Choose again
        ''')
        human()
    elif human_choice in possible_options:
        return human_choice
  • 1
    What is the question? – Thomas May 31 '22 at 11:24
  • 1
    I think you can guess the response from [this answer](https://stackoverflow.com/questions/8532128/function-inputs-and-recursion-in-python). Why not use `repeat until...` logic ? – MyICQ May 31 '22 at 11:25
  • 9
    Recursive calls don't magically pass return from inner calls. – matszwecja May 31 '22 at 11:25
  • Anyway the code you posted simply prints the welcome message and exits... Please always provide a [mre] and explain your exact problem – Tomerikoo May 31 '22 at 11:39
  • A side note, that `elif ...` can just be an `else`. If `x not in y` fails, then the only possible outcome is that `x in y` – Tomerikoo May 31 '22 at 11:41

0 Answers0