Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created July 14, 2013 13:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shigemk2/5994252 to your computer and use it in GitHub Desktop.
#-*- coding:utf-8 -*-"
def psychologist():
print('Please tell me your problems')
while True:
answer = yield
if answer is not None:
if answer.endswith('?'):
print("Don't ask yourself too much questions")
elif 'good' in answer:
print("A that's good, go on")
elif 'bad' in answer:
print("Don't be so negative")
free = psychologist()
print next(free) # # Please tell me your problems
# None
# sendを使うとyieldが渡された値を返す。
free.send('I feel bad') # Don't be so negative
free.send("Why 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment