Scratch My Blocks as Python functions

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Scratch My Blocks as Python functions

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In Scratch you make a custom block in My Blocks. Which Python keyword does the 'define' hat block turn into?
A def
B block
2. Which line runs (uses) a function called jump, like dragging the jump block into a script?
A def jump()
B jump()
3. You define a Scratch My Block once and use it many times. What is the Python version of this?
A Copy and paste the same lines every time you need them
B Define the function once, then call it many times
4. Which function definition is written correctly in Python?
A def dance():
B def dance()
5. A My Block has an input called steps, like 'move (steps)'. How is this input written in Python?
A def move_forward(steps):
B def move_forward:steps

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1def cheer(): AThe call is missing brackets, so the function is named but never run.
2cheer() Bgreet() greet() greet()
3A My Block with an input, like 'jump (height)', becomes a function with a parameter CThis is missing the def keyword, so Python cannot define the function. It also has no colon, so it is a call, not a definition.
4Reuse: define once, then use the My Block many times instead of copying blocks DDefines a new function called cheer, like making a Scratch My Block with the define hat
5cheer() print('Go team!') Edef jump(height):
6def cheer(): print('Go team!') cheer FCalls the function so its code runs, like dragging the My Block into a script

Definitions

def

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___ cheer(): print("Go team!")
2.
def cheer()_ print("Go team!") cheer()
3.
def cheer(): print("Go team!") _____()
4.
def hello(____): print("Hi", name) hello("Zoe")
5.
def bonus(points): print(points _ 10) bonus(5)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A def jump():
B print("Jump!")
C jump
Question 2
A def spin(times):
B print("Spin", times)
C spin(3
Question 3
A def clap():
B print("Clap!"
C clap()
D clap()
Question 4
A def move(steps)
B print("Moving", steps)
C move(10)
Question 5
A function say_hi(name):
B print("Hi", name)
C say_hi("Sam")

Answer Key

Scratch My Blocks as Python functions
Section A: Quick Questions
Q1
A — def
Q2
B — jump()
Q3
B — Define the function once, then call it many times
Q4
A — def dance():
Q5
A — def move_forward(steps):
Section B: Match the Pairs
Q1
def cheer(): → Defines a new function called cheer, like making a Scratch My Block with the define hat
Q2
cheer() → Calls the function so its code runs, like dragging the My Block into a script
Q3
A My Block with an input, like 'jump (height)', becomes a function with a parameter → def jump(height):
Q4
Reuse: define once, then use the My Block many times instead of copying blocks → greet() greet() greet()
Q5
cheer() print('Go team!') → This is missing the def keyword, so Python cannot define the function. It also has no colon, so it is a call, not a definition.
Q6
def cheer(): print('Go team!') cheer → The call is missing brackets, so the function is named but never run.
Section C: Definitions
Q1
def — Makes a Python function, like defining a Scratch My Block once. Run it any time by calling its name, e.g. greet(). Inputs become parameters, so you reuse the code instead of copying blocks.
Section D: Fill in the Blanks
Q1
def cheer(): print("Go team!")
Q2
def cheer(): print("Go team!") cheer()
Q3
def cheer(): print("Go team!") cheer()
Q4
def hello(name): print("Hi", name) hello("Zoe")
Q5
def bonus(points): print(points + 10) bonus(5)
Section E: Spot the Error
Q1
C — Writing only the name does not run the function. Like dragging out a My Block, you must call it with brackets: jump().
Q2
C — The call is missing its closing bracket. The block input 3 must go inside a full pair of brackets: spin(3).
Q3
B — The print call inside the function is missing its closing bracket. It should be print("Clap!").
Q4
A — The def line must end with a colon. It should be def move(steps):.
Q5
A — Python uses the keyword def, not function, to define a function (like the define block in Scratch). It should be def say_hi(name):.