-1

i have been struggling to use this function to trap the errors from a user input.

def user_choice():
            choice = 4
            while choice > 3
                    choice = int(input("what list is your card in"))
            return choice

any ideas would be appreciated. thanks

1 Answers1

0

This can be done simply by implementing an array with the valid arguments you desire then using the in keyword to check if it is there.

def user_choice():
        choice = int(input('what list is your card in?: '))
        valid = [1,2,3]
        if choice in valid:
            return choice
        else: 
            print('oops! must be between 1-3 please try again')
            user_choice()
Marko
  • 142
  • 2
  • 12