0% found this document useful (0 votes)
27 views3 pages

Develop An Elementary Chat Boat For Any Suitable Customer Interaction Application

The document outlines the development of a simple chatbot for customer interaction, featuring a variety of predefined responses to common queries. It includes a Python code implementation that utilizes regular expressions to match user input and provide appropriate replies. The chatbot can handle greetings, inquiries about its name, requests for help, and farewells.

Uploaded by

motenancy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Develop An Elementary Chat Boat For Any Suitable Customer Interaction Application

The document outlines the development of a simple chatbot for customer interaction, featuring a variety of predefined responses to common queries. It includes a Python code implementation that utilizes regular expressions to match user input and provide appropriate replies. The chatbot can handle greetings, inquiries about its name, requests for help, and farewells.

Uploaded by

motenancy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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!

You might also like