📘 Lesson  ·  Lesson 93

Simple Chatbot

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.

इस Project के बारे में

💡 एक नज़र में

एक simple rule-based chatbot जो user के message के keywords के आधार पर जवाब देता है।

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.

सारांश

  • Bot message में keywords जाँचकर matching reply लौटाता है।
  • असली chatbots NLP/ML use करते हैं, पर यह core idea दिखाता है।
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n