def get_confirmation(question):
 while True:
  response = input((u'%s (y/n): ' % question)).lower()
  if (re.match(u'^[yn]', response) is not None):
   break
  print((u"Incorrect option '%s'" % response))
 return (response[0] == u'y')

def get_confirmation ( question ) : while True : response = input ( ( u'%s (y/n): ' % question ) ) . lower ( ) if ( re . match ( u'^[yn]' , response ) is not None ) : break print ( ( u"Incorrect option '%s'" % response ) ) return ( response [ 0 ] == u'y' )
will pose the question to the user and keep asking them until they provide an answer that starts with either a y or an n .