 <p>[EDIT from generator to function]</p> <p>You can try a function:</p> <pre><code>def check_answer(question, answer): while True: current_answer = input(question) if current_answer == answer: break print "Something wrong with question {}".format(question) return current_answer answerX = check_answer("Question about X?\n", "TrueX") answerY = check_answer("Question about Y?\n", "TrueY") answerZ = check_answer("Question about Z?\n", "TrueZ") </code></pre> <p>Not sure if you want to keep the values, but if you need to tweak it, this should give you hints. </p> <p>Results:</p> <pre><code>Question about X? "blah" Something wrong with question Question about X? Question about X? "blah" Something wrong with question Question about X? Question about X? "TrueX" Question about Y? "TrueY" Question about Z? "blah" Something wrong with question Question about Z? Question about Z? "blah" Something wrong with question Question about Z? Question about Z? "TrueZ" </code></pre> <p>Edit per comment:</p> <pre><code>def check_answer(question, answers): while True: current_answer = input(question) if current_answer in answers: break print "Something wrong with question {}".format(question) return current_answer answerX = check_answer("Question about X?\n", ("TrueX", "TrueY") </code></pre>