|
|
|
|
|
by contravariant
1057 days ago
|
|
Best way to think about it is that a generator can throw some questions back to the caller. It always looks a bit messy though. question_bank={'1+1' : '2', '2+3' : '5'}
def Quiz():
for question, correct_answer in question_bank.items():
answer = yield question
if answer == correct_answer:
print('Correct!')
else:
print('Wrong.')
yield 'Finished!'
question = Quiz()
q = next(question)
while q != 'Finished!':
q = question.send(input(q))
|
|