← Back to course
Code Crew G3 / Week 05 / Monday
1/6
Week 05 Β· Functions

Monday

// Steps with names

Monday: Meet the Idea

Rocket writes the five toast steps on his tablet. Then he writes them again. And again! "My hand is getting tired," he says.

Raven looks at his lists. "What do you notice?" she asks. "Every list is the same," Rocket says.

Nova blinks her blue eyes. "Would you like a hint? A group of steps can have a name." Let's help them name the toast steps.

Every morning RAVEN does the same 5 steps to make toast. Instead of writing all 5 every day, Raven gives the steps a NAME: make_toast(). Now Raven just writes 'make_toast()' and the same 5 steps run.

Big Idea
FUNCTION = give steps a NAME.
CALL the name to run the steps.
Reuse the same steps in many places.
function make_toast():
    get bread
    put bread in toaster
    push the lever
    wait until pop
    add banana slices

Define Once, Call Many Times

Writing the steps inside a function is called DEFINING it. Using its name is called CALLING it.

You define a function one time. Then you can call it as many times as you need.

function wave_hello():
    raise your hand
    wave 3 times
    say hello

wave_hello()
wave_hello()
READ THE FUNCTION
  • Read the question.
  • Tap your answer.
How many steps are inside wave_hello?
How many times is wave_hello called?
How many steps run in all?
How many waves happen in all?
Writing the steps of a function is called ____ it.
Using a function by its name is called ____ it.
What two marks go after a function name when you call it?
StatementTrue or false?
A function is a group of steps with a name.?
You must write the steps again every time you call it.?
wave_hello() runs all the steps inside wave_hello.?
A function can only be called one time.?
WHY THIS EXERCISEFunctions save writing and keep steps the same every time.
WRITE A PLANT FUNCTION
  • ?fill the watering can
  • ?function water_plant():
  • ?put the can away
  • ?pour water on the soil
WHY THIS EXERCISEA function is a named sequence. The steps inside still need the right order.
function stretch(): reach up, then touch your toes. Raven calls stretch() 4 times. How many toe touches?
WHY THIS EXERCISEEvery call runs all the steps inside the function.
Try it
Invent a function called silly_walk().
Give it three steps, like hop, spin and march.
Ask a grown-up to call it. Then you do the steps!

Quick Check

Raven calls make_toast() 3 times. Each call runs all 5 steps. How many steps run in all? ____
WHY THIS EXERCISECalling a function runs every step inside it, every time. Programmers reuse functions so they write the steps only once.