21. defpsychologist(): print'Please tell me your problems' whileTrue: answer=(yield) ifanswerisnotNone: ifanswer.endswith('?'): print("Don't ask yourself too much questions") elif'good'inanswer: print"A that's good, go on" elif'bad'inanswer: print"Don't be so negative"
22. >>> free = psychologist() >>> free.next() Please tell me your problems >>> free.send('I feel bad') Don't be so negative >>> free.send("Why I shouldn't ?") Don't ask yourself too much questions >>> free.send("ok then i should find what is good for me") A that's good, go on