Software decides things for you all day: what appears at the top of a feed, whether a photo has your face in it, what word you meant when you mistyped. The part of a program that decides is called an AI model.
Here are five real things software does. Your teacher will take them one at a time. For each one, call out the kind of model you think is behind it.
Choose from these four kinds of model:
| Kind | What it does | Where you meet it when coding |
|---|---|---|
| Generative | Produces something new: text, an image, code | An assistant that drafts a function or explains code |
| Recommendation | Ranks options for one person | What a shop or a feed shows a given user |
| Classifier | Sorts an input into categories | Cat or dog, spam or not, rock or paper |
| Agent | Takes a goal, plans, uses tools, acts in a loop | Software that carries out a multi-step task |
The one you are about to build is a classifier. It takes something in and puts a label on it, and it is the simplest of the four to build by hand.
Go to scratch.mit.edu and click Create to start a new project. Call it Cat or Dog.
You will write all of today's code on the cat sprite that is already there, so you do not need to add anything.
Your guesser asks yes-or-no questions. The player presses y for yes or n for no.
Build this from Events (yellow), Looks (purple), Control (orange), Sensing (light blue) and Operators (green, where the or block lives). The wait until block holds the script until a key goes down.
Read it and predict: if you answer n, what will the cat do?
when green flag clicked
say [Think of a pet: a cat or a dog. Answer with y or n.] for (3) seconds
say [Rule 1. Does it bark?]
wait until <<key [y v] pressed?> or <key [n v] pressed?>>
if <key [y v] pressed?> then
say [I think it is a DOG.] for (4) seconds
stop [this script]
end
Click the green flag and answer y. The cat says DOG, which is right.
Now run it again and answer n. Nothing happens: the script just ends. One rule is not a classifier, it is an opinion. You need a rule for every answer.
Add a second rule underneath the first. The extra wait until waits for the key to come back up: without it, one long press on n would answer every question at once.
Run it and answer n then y. The cat should say CAT.
when green flag clicked
say [Think of a pet: a cat or a dog. Answer with y or n.] for (3) seconds
say [Rule 1. Does it bark?]
wait until <<key [y v] pressed?> or <key [n v] pressed?>>
if <key [y v] pressed?> then
say [I think it is a DOG.] for (4) seconds
stop [this script]
end
wait until <not <key [n v] pressed?>>
say [Rule 2. Does it purr?]
wait until <<key [y v] pressed?> or <key [n v] pressed?>>
if <key [y v] pressed?> then
say [I think it is a CAT.] for (4) seconds
stop [this script]
end
Add the last rule: if it fetches a ball, it is a dog, otherwise it is a cat. This one uses if / else, so every answer now leads somewhere.
Your guesser is finished. It is three rules long, and it is a real classifier.
when green flag clicked
say [Think of a pet: a cat or a dog. Answer with y or n.] for (3) seconds
say [Rule 1. Does it bark?]
wait until <<key [y v] pressed?> or <key [n v] pressed?>>
if <key [y v] pressed?> then
say [I think it is a DOG.] for (4) seconds
stop [this script]
end
wait until <not <key [n v] pressed?>>
say [Rule 2. Does it purr?]
wait until <<key [y v] pressed?> or <key [n v] pressed?>>
if <key [y v] pressed?> then
say [I think it is a CAT.] for (4) seconds
stop [this script]
end
wait until <not <key [n v] pressed?>>
say [Rule 3. Does it fetch a ball?]
wait until <<key [y v] pressed?> or <key [n v] pressed?>>
if <key [y v] pressed?> then
say [I think it is a DOG.] for (4) seconds
else
say [I think it is a CAT.] for (4) seconds
end
Test it the way you would test any program, with cases where you already know the answer.
Three for three. A handful of if/else rules is a genuinely working classifier.
Try these:
You could add more rules, but every new animal needs another one, and they start to contradict each other. This is where hand-written rules run out.
Find a case your guesser gets wrong, then try to fix it with one more rule.
Before you finish, check: you can name an animal it fails on, you added a rule to catch it, and you can say what your new rule broke or nearly broke.
You built a classifier out of rules you wrote yourself. On clear cases it was right every time. On the awkward ones it was confidently wrong, and adding rules made it worse, not better.
A model that learns from examples does not need you to think of every case in advance. That is what you build next.
Today you:
Save your project where your class keeps its work (your teacher will show you where), so you can open it again.
Every lesson in the course is ready to teach like this one. See what else comes with it, and how to order it.