import random import re import sys potv=('yes','ok','yeah','true') notv=('no','wrong','not','false') def askhimsomething(): favourites=['daytime', 'football team', 'kind if sports', 'season of the year', 'film', 'food', 'city', 'kind of juice', 'weather', 'work of art'] reactions=["Wonderful! That's something that we have in common.", "Lovely, my father realy love them too.", "Realy? that's very difficult, but exiting sport. That's not my cup of tea.", "Wow, I absolutely agree with you, the streets look fantastic at this time of the year!", "Yes, it's breathcatching!", "Oh, I always dream to learn to cook it better than my best friend, but the grass is always greener on the other side of the fence, you know.", "That's my dream to visit it one day! Youth likes to wander.", "Mmm, sounds great! I love it! And hunger is the best sauce.", "Woo, that's great, I also like it.", "That's my dream to visit it one day! It's a thing of great beauty."] rea=random.randint(0,8) print ("--What's your favourite %s?" % (favourites[rea])) ans=raw_input() byebye(ans) print reactions[rea] def hewroteaquestion(): answ=raw_input("--That's difficult question. is it about me?\n") byebye(answ) answ=answ.lower() a=re.findall(r'no', answ) if (a!=[]) or (a in notv): answ=raw_input ("--Ok, then, what's your opinion?\n") byebye(answ) print "--Great! I feel the same way." else: print "--Let's stop discussing me, let's talk about you" askhimsomething() def askhisname(): print("--My name is Chat, and what's your name?") imya=raw_input() byebye(imya) im=re.findall('[A-Z][a-z]+', imya) while im==[]: print "--Sorry can't get your name. A word is enough to the wise. But I'm just a robot. Use capital letter." imya=raw_input() byebye(imya) im=re.findall('[A-Z][a-z]+', imya) print("--Should I call you %s?") % (im[0]) otv1=raw_input() byebye(otv1) otv1=otv1.lower() if ((otv1 in notv) or (re.findall(r'no', otv1)!=[])): im=re.findall('[A-Z][a-z]+\s+\w[a-z]+', imya) print("--Should I call you %s?") % (im[0]) otv2=raw_input() byebye(otv2) otv2=otv2.lower() if (otv2 in notv) or (re.findall(r'no', otv2)!=[]): print("--So, tell me without other words how should I call you?") goodname=raw_input() byebye(goodname) print("--Ok, %s, let's chat!") % (goodname) else: print("--Ok, %s, let's chat!") % (im[0]) else: print("--Ok, %s, let's chat!") % (im[0]) def byebye(a): if a=="BYE-BYE": print "--It was a pleasure to chat with you! Good luck! The grand essentials of happiness are: something to do, something to love, and something to hope for." sys.exit() crrep=raw_input() print "--Hey, would you like to talk to me? Let's do it! If you ever want to quit the chat, just print 'BYE-BYE'. Also I recommend you to use simple answers fo yes-or-no questions." askhisname() crrep=raw_input() while (crrep!="BYE-BYE"): a=re.findall(r'\?', crrep) if (a!=[]): hewroteaquestion() else: print "--Could i ask you something?" otv1=raw_input() byebye(otv1) if ((otv1 in potv) or (re.findall(r'no', otv1)==[])): askhimsomething() else: while ((otv1 in notv) or (re.findall(r'no', otv1)!=[])): print "--Oh, please, could I ask a question?" otv1=raw_input() byebye(otv1) askhimsomething() crrep=raw_input()