ASSIGNMENT 05
Problem Statement : Develop an elementary chat boat for any suitable customer
interaction application
Code :
import re
import random
class SimpleChatBot: def
__init__(self):
self.responses = {
r"hi|hello|hey": ["Hello! How can I assist you today?", "Hi there! What can I do for
you?"],
r"how are you": ["I'm just a bot, but I'm doing great! How about you?", "I'm fine,
thanks for asking!"],
r"your name": ["I am ChatBot, your virtual assistant!", "You can call me
ChatBot."], r"help|support": ["Sure! What do you need help with?", "I’m here to
assist. Please tell me your issue."],
r"bye|goodbye": ["Goodbye! Have a great day!", "Bye! Hope to talk to you again
soon."],
r"(.*)": ["I'm not sure I understand. Can you rephrase?", "Can you clarify that?"]
}
def get_response(self, user_input):
user_input = user_input.lower() for pattern,
responses in self.responses.items(): if
re.search(pattern, user_input):
return random.choice(responses)
return "I'm not sure how to respond to that."
def main(): bot = SimpleChatBot()
print("ChatBot: Hello! Type 'bye' to exit.")
while True: user_input = input("You: ")
if user_input.lower() in ["bye", "exit", "quit"]:
print("ChatBot: Goodbye! Have a great day!")
break
response = bot.get_response(user_input)
print(f"ChatBot: {response}")
if __name__ == "__main__":
main()
Output :
ChatBot: Hello! Type 'bye' to exit.
You: hello
ChatBot: Hi there! What can I do for you?
You: what is your name?
ChatBot: I am ChatBot, your virtual assistant!
You: I need help
ChatBot: Sure! What do you need help with?
You: bye
ChatBot: Goodbye! Have a great day!