← Back to course
Code Crew G3 / Week 05 / Wednesday
3/6
Week 05 Β· Functions

Wednesday

// Steps with names

Wednesday: Inputs (Parameters)

Rocket built a greeting machine. It says "Hello, Rocket!" every time. "But I want it to greet Raven too," he says.

Raven reads the steps. "What do you notice? Only the name needs to change."

Nova hovers close. "Here is a hint. A function can take an input. The input tells it what to work on." Let's help them give the function an input.

Some functions take an INPUT (also called a PARAMETER). The input tells the function WHAT to work on.

function greet(name):
    say 'Hello, ' + name + '!'

greet('Rocket')   β†’  Hello, Rocket!
greet('Raven')    β†’  Hello, Raven!
greet('YOU')      β†’  Hello, YOU!

Your turn

What does each call PRINT? Write the output.

greet('Mom') β†’ ___________________
greet('Coda') β†’ ___________________
greet('Mr. T') β†’ ___________________

Build a Function

Design a function called MAKE_BRACELET that takes a color as input.

Write the steps inside.

function make_bracelet(color):
1. ______________________________________
2. ______________________________________
3. ______________________________________
4. ______________________________________
β—‡ PARTNER MOVE
Trade with a partner. They CALL your function with a color.
You pretend to be the computer and run the steps out loud.

Input Practice

INPUTS CHANGE THE OUTPUT
  • Read the question.
  • Tap your answer.
greet(name) says Hello, then the name. What does greet(Nova) say?
In greet(name), what is the parameter?
function double(n): say n + n. What does double(4) say?
Why give a function an input?

Quick Check

greet(name) says Hello, then the name. What does greet('Sam') say? ____
WHY THIS EXERCISEA parameter lets one function work on different inputs. A program can greet each user by name this way.
← Tuesday