Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

1.1 (3 of 4): Pattern recognition

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

40 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

How does your phone guess your next word?

You type "see you". Your phone suggests "soon". It is often right.

The phone has seen that people often write "soon" after "see you". It found a pattern. Programmers use the same skill to solve problems.

Key words

WordWhat it meansExample
PatternSomething that repeats or looks alike.2, 4, 6, 8
Pattern recognitionFinding patterns to help solve a problem.two apps both need a login
TrendA change that goes in one direction over time.the bus is later each day
SimilarityA way that two things are alike.both use a password
PredictionA careful guess about what comes next.Friday will be 6 minutes late
AssumptionSomething you believe is true but have not checked.there is no strike on Friday

The cells students fill in are left blank in this preview.

Quick check: spot the pattern

Have a go

Quick check: spot the pattern

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Why look for patterns?

Pattern recognition means finding what repeats or looks alike. Its purpose is to save time.

If a new problem looks like an old one, you can reuse the old solution. You do not start again.

Worked example: a trend

DayMinutes lateChange from the day before
Monday2none
Tuesday3up 1
Wednesday4up 1
Thursday5up 1
Friday?up 1, so 6 (a prediction)

The cells students fill in are left blank in this preview.

Read the trend

Look at the last column. The bus is 1 minute later each day. That is a trend: a change in one direction.

You predict that Friday is 5 + 1 = 6 minutes late. A prediction is a careful guess, not a fact.

Make a prediction

Have a go

Make a prediction

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Three ways to use patterns

UseWhat you look forExample
1 Trends and similaritiesChanges over time, and likeness inside one problem or between two problems.Every enemy in a game moves left. A cinema booking is like a doctor booking.
2 Existing solutionsA solved problem that looks like this one.Reuse the login code from your last project.
3 Predictions and assumptionsWhat will probably happen next, and what you accept as true.Next month has the same sales. You assume no new shop opens.

The cells students fill in are left blank in this preview.

Match the new problem to an old solution

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Watch: from a pattern to code

Press Play on the short film below. It finds the pattern in the bus table and turns the change that repeats into one step in code. Then it reuses that code for a new problem. Watch what happens when the pattern breaks.

Film: pattern recognition

Pattern recognition

Every scene, as text

  1. Pattern recognition means finding what repeats or looks alike. The bus is 2 minutes late on Monday, 3 on Tuesday, 4 on Wednesday and 5 on Thursday: up 1 each day. A change that goes in one direction over time is a trend.
  2. The change that repeats becomes one step in code, the lesson's Try it code. step = tuesday - monday works out the step, 1. friday = tuesday + step * 3 goes three steps on from Tuesday: Wednesday, Thursday and Friday. print(friday) prints 6, a prediction for Friday.
  3. Sales of 10, 20 and 30 pounds a day look like a new problem, but they go up by the same step each day, like the bus. So the old code is reused: only the numbers for monday and tuesday change, to 10 and 20, and the last three lines are the bus code unchanged. It prints 50 for Friday: Wednesday is 30, Thursday 40 and Friday 50. That is the purpose of pattern recognition: reuse what you already know, and save time.
  4. Myth (false): a pattern always carries on. A pattern carries on only while nothing changes. A bus strike on Friday breaks the trend, so the prediction of 6 minutes late is wrong.
  5. The cure: write down your assumption, and check it: is there a strike on Friday? The comment at the top says it: no strike on Friday. An assumption is something you believe is true but have not checked. The program still prints 6, a prediction: a careful guess, not a fact.

Try it: use the pattern

Code: python
monday = 2
tuesday = 3
step = tuesday - monday
friday = tuesday + step * 3
print(friday)

# The step is 1. Tuesday is 3, so Wednesday 4, Thursday 5, Friday 6.
# Change tuesday to 5 and run it again.

Make a free account to save your work and track your progress.

Patterns can break

Warning

Many people think a pattern always carries on. It does only while nothing changes. A bus strike on Friday breaks the trend. Write down your assumption, and check it.

Your turn: use a pattern in code

Each function uses a pattern.

  1. next_number gives the next number when the step is the same each time. For 5 and 8 it gives 11.
  2. next_week_savings is the same problem with money. Reuse your idea from step 1.
  3. is_going_up says True if three numbers show a rising trend: each one is bigger than the one before.

Press Run Tests to check.

Code: python
def next_number(first, second):
    # The numbers go up by the same step each time.
    # Give back the next number. For 5 and 8 the next is 11.
    return 0


def next_week_savings(last_week, this_week):
    # Savings grow by the same amount each week.
    # Give back the money saved next week.
    return 0


def is_going_up(first, second, third):
    # Three numbers in time order, such as goals in three matches.
    # Give back True if each number is bigger than the one before it.
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Exit quiz

Have a go

Exit quiz

6 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Remember

Important

Find trends and similarities. Reuse old solutions. Make predictions, and write down your assumptions.

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.