-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_chat.py
More file actions
45 lines (36 loc) · 1.03 KB
/
simple_chat.py
File metadata and controls
45 lines (36 loc) · 1.03 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
38
39
40
41
42
43
44
can_talk = True
responses = {
"hello,hi,sup": "Hey you. Whats up?",
"bye, goodbye, later, ltr": "Alrite, Later.",
"name, title": "Simple Chat Bot",
"age": "Im new",
"exit,close": "Closing program"
}
def check_matches(chat_key, user_input):
matches = chat_key.split(",")
question_array = user_input.split(" ")
counter = 0
for match in matches:
for word in question_array:
if set(word.strip().lower()) == set(match.strip().lower()):
counter = counter + 1
return counter
def get_response(question):
matched_key = ""
for key in responses:
max_matches = 0
matched_count = check_matches(key, question)
if matched_count > max_matches:
matched_key = key
max_matches = matched_count
return matched_key
def talk():
global responses
response = input("You:")
res = get_response(response)
if not res:
print("I don't understand")
else:
print(responses[res])
while can_talk:
talk()