title: Is there a way to validate user input using a variable format?
body: <p>The project I'm working on is an Airplane class that contains lists of seats. Below is an example of the list of seats. I am trying to create a try/except block within my book_seat() to check if the user inputs a correct string to match one of the seats, ie. 'Seat 1' or even up to 'Seat 200'. Is there a way I can scan the list via a format or maybe a regular expression? I am having trouble thinking of a better way to ask this question so here is an example of what I'm trying to do:</p>
  <pre><code>while True:
      try:
          user_input = input(&quot;Please enter a seat number to book. (ie. 'Seat 1'))
          if user_input == 'Seat {}'.format(int):
              execute_function()
      except:
          print(&quot;sorry, you're entry is not valid. Please try again&quot;)
  </code></pre>
  <pre><code>[['Seat 1', Seat('Economy',False)], ['Seat 2', Seat('Economy',False)], ['Seat 3', Seat('Economy',False)], ['Seat 4', Seat('Economy',False)], ['Seat 5', Seat('Economy',False)], ['Seat 6', Seat('Economy',False)], ['Seat 7', Seat('Economy',False)], ['Seat 8', Seat('Business',False)], ['Seat 9', Seat('Business',False)], ['Seat 10', Seat('First',False)]]
  </code></pre>