How to Build a Simple Python Chatbot (No AI Required!)

Day 27 of 100 Days Coding Challenge: Python

About a year ago, I was trying to get help from a state government website—you know, the kind that promises “24/7 assistance” via a chirpy chatbot. Except, instead of assistance, I got a face full of code errors. Repeatedly. The bot was supposed to reduce agent time, but apparently, it had decided to take a permanent coffee break. I asked nicely, refreshed, and even pleaded. Nothing. That little robot ghosted me.

Naturally, I got curious—how hard could it be to build a simple chatbot that actually responds? And here we are: this is not some ultra-sophisticated AI oracle; this is a humble, pre-AI chatbot. No deep learning, no fancy brain. Just old-school logic and a love for the “if-else” life.

Today’s Motivation / Challenge

Today’s challenge is nostalgic. We’re going back to a simpler time—before neural networks and hallucinating chatbots—when your digital assistant was more rule-follower than mind-reader. This project connects to that curious urge we all get when tech breaks: “Could I make something that works better than this?” Well, maybe. Today’s your chance to try.

Purpose of the Code (Object)

This code creates a chatbot that responds to common phrases using plain, predictable rules. It doesn’t learn, guess, or improvise. Instead, it listens for keywords and responds accordingly—like a polite robot butler who doesn’t like surprises.

AI Prompt

Build a rule-based chatbot in Python that recognizes user input using keyword matching and gives relevant responses about greetings, time, weather (simulated), jokes, and simple math. Add a fallback response for anything it doesn’t understand.

Functions & Features

  • Recognizes greetings, goodbyes, and help requests
  • Simulates a weather response (pure imagination)
  • Tells the current time using your system clock
  • Solves basic math expressions (like “What is 3 + 5?”)
  • Tells a (very polite) joke
  • Politely admits confusion when it doesn’t know what you said

Requirements / Setup

  • Python 3.x
    (No external libraries are needed—just plain Python)

Minimal Code Sample

if “time” in user_input:

    current_time = datetime.datetime.now().strftime(“%H:%M:%S”)

    return f”The current time is {current_time}.”

Checks if the user asked for the time and responds with the current system time.

Rule Based Chatbot

Notes / Lessons Learned

The first basic chatbot worked great. So naturally, I got ambitious. I layered on more logic, more keywords, and more “features.” That’s when it happened: chaos. The code refused to run. I suspected a directory issue—maybe I saved the file in the wrong place? Nope. The file was there. It was my code that was broken, all because of one sneaky extra quote at the end of a string.

Lesson? Python is picky about quotation marks—and for good reason. Mixing ” and ‘ or doubling up can cause a silent meltdown. Also, watch your syntax coloring. If your code suddenly lights up like a Christmas tree, it’s probably not because you’re a genius. It’s because something’s off.

Also, rule-based bots are loyal but very literal. Misspell one keyword—like typing “wether” instead of “weather”—and it freezes like a deer in headlights:

“Hmm… I’m not sure how to respond to that. Try saying ‘help’.”

Still, there’s something rewarding about building a little machine that answers you. In fact, I’m now dreaming of creating a text-based adventure game where the chatbot acts as the narrator and dungeon master. Primitive? Yes. Promising? Absolutely.

Optional Ideas for Expansion

  • Add real weather data using an API like OpenWeatherMap
  • Allow fuzzy matching so it understands similar words or typos
  • Turn it into a text-based game with branching dialogue

Leave a Reply

Your email address will not be published. Required fields are marked *