forked from CSEdgeOfficial/Python-Programming-Internship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTASK-7.py
More file actions
26 lines (22 loc) · 895 Bytes
/
TASK-7.py
File metadata and controls
26 lines (22 loc) · 895 Bytes
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
import nltk
from nltk.chat.util import Chat, reflections
# Define pairs of patterns and responses
pairs = [
(r'hi|hello|hey', ['Hello!', 'Hey there!', 'Hi! How can I help you?']),
(r'how are you?', ['I\'m doing well, thank you!', 'I\'m good, thanks for asking!']),
(r'what\'s your name\??', ['I\'m a chatbot!', 'You can call me ChatBot.']),
(r'(.*) your name\??', ['I\'m a chatbot!', 'You can call me ChatBot.']),
# Add more patterns and responses as needed
]
# Create a Chatbot instance
chatbot = Chat(pairs, reflections)
print("Welcome! Type 'quit' to end the conversation.")
# Start the conversation loop
while True:
user_input = input("You: ")
if user_input.lower() == 'quit':
print("ChatBot: Bye! Have a great day!")
break
else:
response = chatbot.respond(user_input)
print("ChatBot:", response)