[Solved] Checking user input python [closed]


You convert the user’s input to a string (str(input('What ...'))) but compare it to integers in inputCheck. Since there is no else path in inputCheck, nothing happens when you enter a “valid” choice.

Also, if you’re using Python 2, using input is not what you want, raw_input is the way to go (see, for example What’s the difference between raw_input() and input() in python3.x?).

Other than that, recursively calling menuChoice whenever the user enters an illegal choice is quite probably a bad idea: enter an illegal choice a few hundred or thousand times and your program will crash (apart from waste a lot of memory). You should put the code in a loop:

while True:
    userChoice = str(raw_input('What Would You Like To Do? '))
    if userChoice in valid:
        inputCheck(userChoice)
        break
    else:
        print('Sorry But You Didnt Choose an available option... Try Again')

1

solved Checking user input python [closed]