-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
152 lines (114 loc) · 4.09 KB
/
Copy pathchatbot.py
File metadata and controls
152 lines (114 loc) · 4.09 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# ============================================================
# Project Title : Rule-Based AI Chatbot
# Internship : DecodeLabs AI Internship
# Description:
# This project is a simple Rule-Based AI Chatbot.
# It responds to predefined user inputs using
# if-elif-else statements and runs continuously
# until the user exits.
# ============================================================
# ---------------- IMPORT LIBRARIES ---------------- #
import datetime
import random
# ---------------- CHATBOT RESPONSES ---------------- #
greetings = [
"Hello! Nice to meet you.",
"Hi! How can I help you today?",
"Hey! Welcome."
]
how_are_you = [
"I'm doing great. Thanks for asking!",
"I'm fine. Hope you're doing well too!",
"Everything is working perfectly!"
]
jokes = [
"Why do programmers prefer dark mode? Because light attracts bugs!",
"Why did the Python developer go broke? Because he used up all his cache!",
"Debugging is like being a detective in a crime movie where you're also the criminal."
]
# ---------------- DISPLAY INTRO ---------------- #
def show_intro():
print("=" * 60)
print(" RULE-BASED AI CHATBOT")
print("=" * 60)
print("Hello! I am a simple AI Chatbot.")
print("Type 'help' to see available commands.")
print("Type 'bye' anytime to exit.")
print("=" * 60)
# ---------------- HELP MENU ---------------- #
def show_help():
print("\nYou can ask me the following questions:\n")
print(" hello")
print(" hi")
print(" hey")
print(" how are you")
print(" your name")
print(" who made you")
print(" what is ai")
print(" what is python")
print(" tell me a joke")
print(" date")
print(" time")
print(" thank you")
print(" bye\n")
# ---------------- CHATBOT LOGIC ---------------- #
def chatbot():
while True:
user = input("\nYou : ").strip().lower()
# Empty Input
if user == "":
print("Bot : Please type something.")
continue
# Greetings
elif user in ["hello", "hi", "hey"]:
print("Bot :", random.choice(greetings))
# How are you
elif user == "how are you":
print("Bot :", random.choice(how_are_you))
# Name
elif user in ["your name", "what is your name"]:
print("Bot : My name is ChatBot.")
# Creator
elif user == "who made you":
print("Bot : I was created as an AI internship project using Python.")
# AI
elif user == "what is ai":
print("Bot : AI stands for Artificial Intelligence.")
print("Bot : It enables computers to perform tasks that normally require human intelligence.")
# Python
elif user == "what is python":
print("Bot : Python is an easy-to-learn programming language.")
print("Bot : It is widely used for AI, web development, automation and data science.")
# Joke
elif user == "tell me a joke":
print("Bot :", random.choice(jokes))
# Date
elif user == "date":
today = datetime.date.today()
print("Bot : Today's date is", today.strftime("%d-%m-%Y"))
# Time
elif user == "time":
current_time = datetime.datetime.now().strftime("%I:%M:%S %p")
print("Bot : Current time is", current_time)
# Thank You
elif user in ["thanks", "thank you"]:
print("Bot : You're welcome! Happy to help.")
# Help
elif user == "help":
show_help()
# Exit
elif user in ["bye", "exit", "quit"]:
print("\nBot : Thank you for chatting with me.")
print("Bot : Have a wonderful day!")
break
# Default Response
else:
print("Bot : Sorry, I don't understand that question.")
print("Bot : Type 'help' to see the available commands.")
# ---------------- MAIN FUNCTION ---------------- #
def main():
show_intro()
chatbot()
# ---------------- PROGRAM STARTS HERE ---------------- #
if __name__ == "__main__":
main()