What it shows
The bot scans your sentence for keywords and picks a stored reply. It shows how simple chatbots work and why they fail on things they have no rule for, which is a good lesson for AI literacy.
The science
A rule-based chatbot has no understanding. It checks whether a keyword appears in the lower-cased text and prints the reply stored for it. It works only for the rules the programmer wrote. Modern AI chatbots learn patterns from huge amounts of text instead, but they can also make mistakes, so comparing the two helps students see what AI really does.
Materials
Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A computer, laptop or phone with a browser (free)
- Python 3 with IDLE, or the free Thonny editor, or an online Python runner (all free)
- A notebook and a pencil
Safety
This project uses safe, everyday materials. Still, read the rules below with a parent before you start.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Create bot.py and write the rules: rules = {"hello": "Namaste! How can I help?", "exam": "Revise a little every day and sleep well.", "name": "I am a small Python bot.", "bye": "Goodbye!"}.
Print a welcome line with print("Type bye to stop").
Start while True: and read text = input("You: ").lower().
Add for key in rules: on the next line and below it if key in text: print("Bot:", rules[key]) then break.
Align an else with the for loop: else: print("Bot: I did not understand that"). The else of a for runs when no break happened.
Add if "bye" in text: break after the loop so that the chat ends after the goodbye reply.
Chat with the bot with 10 sentences and note which it failed on, for example "hi" instead of "hello".
Add three more rules and a list of synonyms for hello (hi, hey, namaste) with a loop over the list.
What you should see
The bot answers sentences containing its keywords, says it did not understand otherwise, and stops at bye. You can list its failures to see its limits.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1Does this bot understand language?
No, it only matches keywords with stored replies.
2Why use lower()?
So Hello and hello both match.
3How is a modern AI chatbot different?
It learns patterns from large amounts of text rather than following hand-written rules.
4What does the for else do?
The else part runs when the loop finishes without a break.
Take it further
Use random.choice on a list of replies for each keyword so the bot does not repeat itself.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Computer & office
Computer Fundamentals Study Book
The complete study notes, practice questions and glossary for Computer Fundamentals
