Codiqo

Understanding AI · lesson 2 of 60 · about 5 minutes

Rules vs Learning

See the difference between a program that follows rules someone wrote and one that learns from examples.

What you'll learn

  • Describe a rule-based program
  • Describe a program that learns from examples
  • Explain why some jobs are too messy for hand-written rules

Programs that follow rules

Most programs follow rules a person wrote: if the price is over £50, delivery is free. The program does exactly what the rules say, every time.

Rules work brilliantly when the job is clear and the rules are easy to write down.

A rule written by a person. `if` checks a condition; the line under it only runs when the condition is true.

price = 60
if price > 50:
    print("Free delivery")
else:
    print("Delivery costs 3")

Output

Free delivery

When rules aren't enough

Now try writing rules for spotting a cat in a photo. Pointy ears? So do foxes. Whiskers? So do dogs. Cats can be curled up, half hidden, in the dark.

For messy jobs like this, nobody can write all the rules. Instead, we show a program thousands of photos labelled cat and not cat, and it learns the patterns itself. That's machine learning.

Tip

Rules: a person writes the pattern. Learning: the program finds the pattern in examples.

Now try it yourself

This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.