{"id":173,"date":"2026-09-03T08:52:01","date_gmt":"2026-09-03T08:52:01","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=173"},"modified":"2026-09-03T08:52:01","modified_gmt":"2026-09-03T08:52:01","slug":"develop-simple-rule-base-chatbot","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2026\/09\/03\/develop-simple-rule-base-chatbot\/","title":{"rendered":"Develop simple rule base chatbot."},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">import re\n\ndef simple_chatbot(user_input):\n    \"\"\"\n    A simple rule-based chatbot for Indian contexts.\n    \"\"\"\n    # Convert input to lowercase for easier matching\n    user_input = user_input.lower().strip()\n\n    # Define rules and responses\n    if re.search(r'hello|hi|hey|namaste', user_input):\n        return \"Namaste! How can I help you today?\"\n\n    elif re.search(r'how are you', user_input):\n        return \"I'm doing great, thank you for asking! How about you?\"\n\n    elif re.search(r'what is your name|who are you', user_input):\n        return \"I'm a simple rule-based chatbot, your virtual assistant!\"\n\n    elif re.search(r'time|what time', user_input):\n        return \"I don't have a watch, but you can check the time on your phone or computer!\"\n\n    elif re.search(r'weather|temperature', user_input):\n        return \"I can't check the weather right now. Try searching online for your city's forecast!\"\n\n    # India-specific rules\n    elif re.search(r'capital of india', user_input):\n        return \"The capital of India is New Delhi.\"\n\n    elif re.search(r'national sport of india', user_input):\n        return \"While field hockey is the national sport, cricket is the most popular sport in India.\"\n\n    elif re.search(r'currency of india', user_input):\n        return \"The currency of India is the Indian Rupee (\u20b9).\"\n\n    elif re.search(r'pm of india|prime minister', user_input):\n        return \"The Prime Minister of India is Narendra Modi.\"\n\n    elif re.search(r'cricket score', user_input):\n        return \"I don't have live scores. Please check a sports website or app for the latest cricket updates!\"\n\n    elif re.search(r'goodbye|bye|thank you|thanks|dhanyavad', user_input):\n        return \"You're welcome! Have a great day. Dhanyavad!\"\n\n    # Default response\n    else:\n        return \"I didn't understand that. Can you please rephrase?\"\n\n# --- Test the Chatbot ---\nprint(\"Chatbot: Hello! Type 'bye' to exit.\")\nwhile True:\n    user_input = input(\"You: \")\n    if user_input.lower() in ['exit', 'quit', 'bye']:\n        print(\"Chatbot: Goodbye! It was nice talking to you.\")\n        break\n    response = simple_chatbot(user_input)\n    print(f\"Chatbot: {response}\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import re def simple_chatbot(user_input): &#8220;&#8221;&#8221; A simple rule-based chatbot for Indian contexts. &#8220;&#8221;&#8221; # Convert input to lowercase for easier matching user_input = user_input.lower().strip() # Define rules and responses if re.search(r&#8217;hello|hi|hey|namaste&#8217;, user_input): return &#8220;Namaste! How can I help you today?&#8221; elif re.search(r&#8217;how are you&#8217;, user_input): return &#8220;I&#8217;m doing great, thank you for asking! How about [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":96,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,3],"tags":[52,25,26,45],"class_list":["post-173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aiopd","category-bca","tag-aiopd","tag-bca","tag-bca-paper-solution","tag-python"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=173"}],"version-history":[{"count":1,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":174,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/173\/revisions\/174"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/96"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}