Validated user input

--Originally published at Programming Fundaments

In this case you wnat the user to interact with your program; for example, if they want to start making another accion by simply using the srings “yes” and “no”. Example:

endProgram = 0;
while endProgram != 1:

    #Prompt for a new transaction
    userInput = input("Would you like to start a new transaction?: ");
    userInput = userInput.lower();

    #Validate input
    while userInput in ['yes', 'no']:
        print ("Invalid input. Please try again.")
        userInput = input("Would you like to start a new transaction?: ")
        userInput = userInput.lower()

    if userInput == 'yes':
        endProgram = 0
    if userInput == 'no':
        endProgram = 1

The last program has en error, that uin every time you answer something else it will accept it and restart the program

It simply need a codeeditor to export it and that’s it

Examples & More at :http://stackoverflow.com/questions/16635073/validating-user-input-strings-in-python