📘 Lesson · Lesson 93
Simple Chatbot
About this Project
💡 At a Glance
A simple rule-based chatbot that replies based on keywords in the user's message.
The Program
Python
def chatbot(message):
msg = message.lower()
if "hello" in msg or "hi" in msg:
return "Hello! How can I help you?"
elif "name" in msg:
return "I am CodeBot, your assistant."
elif "bye" in msg:
return "Goodbye! Have a nice day."
else:
return "Sorry, I did not understand that."
print(chatbot("Hi there"))
print(chatbot("What is your name?"))
print(chatbot("bye"))Hello! How can I help you?
I am CodeBot, your assistant.
Goodbye! Have a nice day.
Summary
- The bot checks keywords in the message and returns a matching reply.
- Real chatbots use NLP/ML, but this shows the core idea.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.