-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_chatbox.py
More file actions
68 lines (48 loc) · 2 KB
/
Copy pathbasic_chatbox.py
File metadata and controls
68 lines (48 loc) · 2 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
"""
Basic Chatbot
-------------
Author: Adarsh Singh
CodeAlpha Python Programming Internship – Module 1, Task 4
A simple rule-based chatbot. The user types a message, and the bot
replies based on predefined rules (keyword matching). The chat ends
when the user types 'bye'.
Concepts used: if-elif, functions, loops, input/output
"""
def get_bot_response(user_input):
"""
Given the user's message, return an appropriate predefined reply.
Matching is done by checking if certain keywords appear in the
user's (lowercased) message.
"""
message = user_input.lower().strip()
if message == "":
return "Sorry, I didn't catch that. Could you say something?"
elif "hello" in message or "hi" in message or "hey" in message:
return "Hi! How can I help you today?"
elif "how are you" in message:
return "I'm fine, thanks! How about you?"
elif "your name" in message:
return "I'm a simple rule-based chatbot built in Python."
elif "thank" in message:
return "You're welcome!"
elif "bye" in message or "goodbye" in message:
return "Goodbye! Have a great day."
elif "help" in message:
return "You can say things like 'hello', 'how are you', or 'bye' to chat with me."
elif "weather" in message:
return "I can't check live weather, but I hope it's nice where you are!"
elif "joke" in message:
return "Why do programmers prefer dark mode? Because light attracts bugs!"
else:
return "I'm not sure how to respond to that. Try saying 'help' to see what I understand."
def chat():
print("=== Simple Chatbot ===")
print("Type 'bye' to end the conversation.\n")
while True:
user_input = input("You: ")
response = get_bot_response(user_input)
print(f"Bot: {response}")
if "bye" in user_input.lower() or "goodbye" in user_input.lower():
break
if __name__ == "__main__":
chat()