-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
41 lines (30 loc) · 1.16 KB
/
Copy pathchatbot.py
File metadata and controls
41 lines (30 loc) · 1.16 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
"""
Basic Rule-Based Chatbot
Responds to a small set of predefined user inputs with fixed replies.
"""
RESPONSES = {
"hello": "Hi! How can I help you today?",
"hi": "Hello there!",
"how are you": "I'm fine, thanks! How about you?",
"what is your name": "I'm a simple rule-based chatbot.",
"what can you do": "I can chat about a few basic things — try saying hello, asking how I am, or saying bye.",
"thank you": "You're welcome!",
"thanks": "You're welcome!",
"bye": "Goodbye! Have a great day.",
}
DEFAULT_RESPONSE = "I'm not sure how to respond to that. Try saying 'hello', 'how are you', or 'bye'."
EXIT_KEYWORDS = {"bye", "exit", "quit"}
def get_response(user_input):
cleaned = user_input.strip().lower().strip("!?.")
return RESPONSES.get(cleaned, DEFAULT_RESPONSE)
def chat():
print("Chatbot: Hi! Type 'bye' anytime to end the chat.\n")
while True:
user_input = input("You: ")
cleaned = user_input.strip().lower().strip("!?.")
response = get_response(user_input)
print(f"Chatbot: {response}")
if cleaned in EXIT_KEYWORDS:
break
if __name__ == "__main__":
chat()