Skip to main content

What is a function? Pemi defines its first one

The PEEMS team · Published November 10, 2026 · 3 min read

Pemi CS level 'Pemi's first function': a 'define function stair' block and three 'call function' blocks guiding Pemi up a staircase to a flag

A function is a named group of commands you can call again and again. This post uses a Pemi CS level and a lemonade recipe to explain defining and calling a function.

Imagine you have a lemonade recipe: squeeze the lemon, add sugar, add water, stir. Today your child makes one glass; tomorrow, three. Would you copy the recipe out three times, or just say "follow the lemonade recipe"? That "name for a series of steps" is exactly the idea of a function in programming.

So what is a function?

A function is a group of commands with a name, so you can use it again and again. Two things are worth telling apart:

  • Defining a function: writing the steps down once and giving them a name, like writing the recipe.
  • Calling a function: saying "follow that recipe". Each call runs the whole group of commands.

The benefits are very down to earth: programs get shorter, easier to read, and when something needs fixing you change it in just one place.

The level: Pemi defines "stair"

In the Pemi CS level "Pemi's first function", Pemi has to climb three steps to reach a flag. Every step needs the same series of moves: forward one, turn left, forward one, turn right.

Pemi CS function level: a define-function block named stair and three call-function blocks, with Pemi at the foot of the stairs

Instead of snapping those four blocks together three times, the student:

  1. Defines a function called stair that holds the four blocks.
  2. Calls stair three times.

Press run and Pemi climbs all the way up. If the staircase gets taller, the student just adds one more call block instead of rebuilding the whole sequence.

Ways to explore functions at home

  1. Name a routine. "Getting ready for school" might mean bag on, shoes on, coat on. Now the name alone stands for the whole series.
  2. Ask "what repeats?" When your child describes a long series of steps, look for a chunk that appears more than once and give it a name.
  3. Let the "function" take extra information. For example, "make lemonade for 3 people". This is a later step, once simple functions feel familiar.

Questions to talk about with your child

  • In your morning, is there a series of steps you do over and over that we could give a name?
  • If we change one step inside the function, what else changes with it?

Frequently asked questions

How is a function different from a loop? A loop repeats the same piece of code several times in a row. A function is a named piece of code that you can call from different places whenever you need it.

What age can children learn functions? There is no single milestone. The idea of "naming a series of steps" can start early through everyday games. Writing functions in text blocks or Python tends to suit students who are already comfortable with loops and conditions.

Do you have to know Python first? No. Students can meet the idea with blocks first, as in the level above, and write it in Python when they are ready.

Are functions hard? The idea is close to a recipe. The part that most often trips people up is telling "define" from "call", and stepping through the program one step at a time makes it easy to see.

Want to try it together?

Pemi CS has more than 3,000 levels, including levels about functions. It is open now and international families are welcome to register their interest by email.

Keep reading: From block coding to Python: when is the right time to switch? · Your first Python: for loops and if/else

The PEEMS team

Nov 10, 2026

Switching to Python too early frustrates children; too late and they get bored. This article lists signs of readiness, a path from picture blocks to text blocks to Python, and why ideas should come before syntax.

Nov 10, 2026

A first Python snippet with for and if/else is really the text blocks your child already knows, written out as code. This post reads a Pemi CS level that counts red and green signs, line by line.

Nov 10, 2026

To check whether a shelf is in order, compare each pair of neighbours. This post reads a Python is_sorted function through a Pemi CS level.