Validating text input
attribute works with the following input types: text, search, url, tel, email, and password.
Tip: Use the global title attribute to describe the pattern to help the user.
So our general format is going to look like this: food = ['pizza', 'burgers', 'sushi'] while True: answer = input('Would you like to get pizza, burgers, or sushi?
') if answer.lower() in food: break print("I don't know of a restaurant near here.".format(answer)) print("Okay, let's have .".format(answer)) Would you like to get pizza, burgers, or sushi? The isdigit method of a string makes sure that all of the character in the string are digits.
Our if statement is starting to get rather complicated. We do this with a try/except block, like this: If you are not familiar with try/except, it is used to catch errors.