-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp5.py
More file actions
executable file
·37 lines (33 loc) · 1.29 KB
/
Copy pathmp5.py
File metadata and controls
executable file
·37 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import random
class Doctor:
hedges = ("Please tell me more.", "Many of my patients tell me the same thing.", "Please continue.")
qualifiers = ("Why do you say that ", "You seem to think that ", "Can you explain why ")
replacements = {"I":"you", "me":"you", "my":"your", "we":"you", "us":"you", "mine":"yours"}
def reply(self,sentence):
probability = random.randint(1, 4)
if probability == 1:
return random.choice(self.hedges)
else:
return random.choice(self.qualifiers) + self.changePerson(sentence)
def changePerson(self, sentence):
words = sentence.split()
replyWords = []
for word in words:
replyWords.append(self.replacements.get(word, word))
return " ".join(replyWords)
def greeting(self):
print("Good morning, I hope you are well today.")
print("If you would like to exit the conversation just type: QUIT")
print("What can I do for you?")
def signoff(self):
print("Have a nice day!")
def main():
Doc = Doctor()
Doc.greeting()
while True:
sentence = input("\n>> ")
if sentence.upper() == "QUIT":
Doc.signoff()
break
print(Doc.reply(sentence))
main()