computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

🧠

🎓

⏱ 20 min

Free

How AI Learns

Rules written by people versus patterns learned from examples. Which is AI?

🎯 What you will learn

  • Rules are written by people
  • Learning finds patterns in examples
  • Most modern AI learns from data

👋 Let’s get started!

Traditional software follows rules that a person wrote. Machine learning is different: it looks at many examples and finds the pattern itself. Let’s compare the two. 🧠

🪜 Step by step

1. 📜 Hand-written rules

A person decides every step. This always works the same way.

def is_fruit(name):
    return name in ["apple", "banana"]

print(is_fruit("apple"))
2. 📚 Learned from examples

The program gets examples with answers and works out its own pattern.

examples = [(1, "cat"), (2, "cat"), (8, "dog"), (9, "dog")]
3. 🔍 Patterns, not facts

A learned pattern is only as good as its examples.

print(len(examples), "examples")

🧪 Try it!

Change the code and press ▶ Run to see what happens. You can’t break anything!

Rules vs examples

def is_fruit(name):
    return name in ["apple", "banana"]

print(is_fruit("apple"))
print(is_fruit("car"))
examples = [(1, "cat"), (2, "cat"), (8, "dog"), (9, "dog")]
print(len(examples), "examples")

🎨 Unplugged activity

🧠 Write down 5 things you think a phone camera “knows” about your face. For each one, ask: was it a rule someone wrote, or a pattern from examples?

Rule or learning?

# Rule: if the number is over 10, say big
def size(n):
    return "big" if n > 10 else "small"
print(size(12))

📖 Key words

Tap a card to flip it over!

Rule
A step a person writes 📜
Machine learning
Finding patterns from examples 🔍
Example
A piece of data with an answer 📚

🏆 Challenge

Print how many examples are in the list “examples” (three of them). Press ▶ Run.

Challenge

examples = [(1, "cat"), (2, "cat"), (8, "dog")]

Knowledge Check Quiz

  1. What does machine learning use to find patterns?
  2. Which is hand-written?
  3. Why can a learned pattern be wrong?
Next lesson →