5 ms·
I am a python noob and this is going to take me some time to process.
by noman-land 3y ago
I am a python noob and this is going to take me some time to process.
- contravariant 3y agoBest 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))