-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonalChatAssistant.py
More file actions
51 lines (38 loc) · 1.48 KB
/
Copy pathPersonalChatAssistant.py
File metadata and controls
51 lines (38 loc) · 1.48 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
45
46
47
48
49
50
51
#Rule based AI Python ChatBot
import datetime
import time
name = input("Welcome . Enter your name : ")
hour = datetime.datetime.now().hour
if(hour>=4 and hour<12):
print('Good Morning', name , '!!!')
elif(hour>=12 and hour<17):
print('Good Afternoon', name , '!!!')
elif(hour>=17 and hour<21):
print('Good Evening', name , '!!!')
else:
print('Good Night', name , '!!!')
print("Hello ! Welcome to your Personal Chat Assistant or your Chatbot.")
print("You can ask me basic questions , and type 'Bye' to exit from the bot .")
#Chatbot Memory Creation [ dictionary of responses ]
responses = {
"hello":"Hii , Welcome . How can I help you ?",
"how are you":"I am very fine . Thank you .",
"who are you":"I am a smart AI Chatbot .",
"motivate me":"Keep going . Every bugof your project makes you a better developer .",
"happy":"Great to hear that .",
"joke":"Why was the computer cold ?.....It left its WINDOWS open ."
}
#Method / Function to get response of ChatBot
def getResponseOfBot(userQuestion):
userQuestion = userQuestion.lower()
for eachKey in responses:
if eachKey in userQuestion:
return responses[eachKey]
return "Sorry . I am not able to tell that yet .I am still in learning mode .I will learn that soon ."
#Take user input
while True:
userInput = input("Please ask your question :")
reply = getResponseOfBot(userInput)
print("Bot Response : ",reply)
if "bye" in userInput.lower():
break