Develop simple rule base chatbot.

Develop simple rule base chatbot.

import re

def simple_chatbot(user_input):
    """
    A simple rule-based chatbot for Indian contexts.
    """
    # Convert input to lowercase for easier matching
    user_input = user_input.lower().strip()

    # Define rules and responses
    if re.search(r'hello|hi|hey|namaste', user_input):
        return "Namaste! How can I help you today?"

    elif re.search(r'how are you', user_input):
        return "I'm doing great, thank you for asking! How about you?"

    elif re.search(r'what is your name|who are you', user_input):
        return "I'm a simple rule-based chatbot, your virtual assistant!"

    elif re.search(r'time|what time', user_input):
        return "I don't have a watch, but you can check the time on your phone or computer!"

    elif re.search(r'weather|temperature', user_input):
        return "I can't check the weather right now. Try searching online for your city's forecast!"

    # India-specific rules
    elif re.search(r'capital of india', user_input):
        return "The capital of India is New Delhi."

    elif re.search(r'national sport of india', user_input):
        return "While field hockey is the national sport, cricket is the most popular sport in India."

    elif re.search(r'currency of india', user_input):
        return "The currency of India is the Indian Rupee (₹)."

    elif re.search(r'pm of india|prime minister', user_input):
        return "The Prime Minister of India is Narendra Modi."

    elif re.search(r'cricket score', user_input):
        return "I don't have live scores. Please check a sports website or app for the latest cricket updates!"

    elif re.search(r'goodbye|bye|thank you|thanks|dhanyavad', user_input):
        return "You're welcome! Have a great day. Dhanyavad!"

    # Default response
    else:
        return "I didn't understand that. Can you please rephrase?"

# --- Test the Chatbot ---
print("Chatbot: Hello! Type 'bye' to exit.")
while True:
    user_input = input("You: ")
    if user_input.lower() in ['exit', 'quit', 'bye']:
        print("Chatbot: Goodbye! It was nice talking to you.")
        break
    response = simple_chatbot(user_input)
    print(f"Chatbot: {response}")