#!/usr/bin/env python
#


import random


output = "Tell me what you're feeling (when you want to stop, "
output = output + "type the word stop):\n "
allreplies = ["Patient replies\n"]
flag = 1
friendname = "lkajoieare" # a non-name
lastoutput = "kjlkjlk"
friendnamecoming = 0
havefriendname = 0
while flag == 1:
	if(lastoutput == output):
		output = "Please go on.\n"
	inpatient = input (output)
	lastoutput = output
	allreplies.append(output[0:len(output)-1])
	allreplies.append(inpatient)
	allreplies.append(" ========== ")
	mywords = inpatient.split(" ")
	if (len(mywords) == 1) & (friendnamecoming == 1):
		havefriendname = 1
		friendname = mywords[0]
	x = random.random() 
	if x < 0.3:
		output = "Interesting. What else?\n"
	elif x < 0.5:
		output = "I'm listening.\n"
	elif x < 0.6:
		output = "Yes.\n"
	elif havefriendname == 0:
		y = mywords[0]
		if ("I'm" == y)|("I" == y)|("I" == y):
			output = "You?\n"
		else:
			output = "Do you want to tell me about your friends?\n"
	else:
		output = ("Tell me more about ") + friendname + (".\n")
	if ("stop" in mywords) & (len(mywords) == 1):
		flag = 0
		print("Ok. Thanks and take care")
	elif ("father" in mywords) | ("dad" in mywords):
		if x > 0.6:
			output = "Tell me more about your father.\n "
		else:
			output = "What do you feel about your father.\n "
	elif (friendname in mywords):
		if x > 0.5:
			output = ("Speak to me about ") + friendname + (".\n")
		else: 
			output = ("What would ") + friendname + (" think about that?\n")
	elif ("violence" in mywords) | ("violent" in mywords):
		if x > 0.6:
			output = "Why would anyone want to be violent?\n" 
		else:
			output = "Are you interested in guns?\n" 
	elif (("strangle") in mywords) | (("kill") in mywords):
		output = "Why these feelings?\n"
	elif (("hate") in mywords) | (("hates") in mywords):
		if x > 0.6:
			output = "Do you think there is too much hate in the world.\n"
		else:
			output = "Why so much hate?\n"

	elif ("mother" in mywords) | ("mom" in mywords):
		if x > 0.4:
			output = "Do you think about your mother often?\n" 
		else:
			output = "Speak to me about your Mom\n" 
	elif ("no" in mywords) & ("friends" in mywords):
		output = "Why no friends?\n" 
	elif ("friends" in mywords) | ("friend" in mywords):
		if x < 0.7:
			output = "Tell me more about your friends\n" 
		else:
			output = "What the name of your best friend?\n" 
			friendnamecoming = 1
	elif "sad" in mywords:
		output = "Why sad?\n"
	elif "school" in mywords:
		output = "What do you like least about school?\n" 
	elif "teacher" in mywords:
		output = "Tell me more about that teacher\n" 
	elif "dying" in mywords:
		output = "What do you think about death?\n" 
	elif "death" in mywords:
		output = "Death is scary, isn't it?\n" 

for line in allreplies:
	print(line)
