Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1def show(): score = 5 print(score) | Aname is a global variable, made outside all functions, so greet() can use it | |
| 2name = "Sam" def greet(): print(name) | Bdef double(num): print(num * 2) | |
| 3A variable created inside a function is local and only exists while that function runs | CNameError: score is a local variable made inside show(), so it does not exist outside the function | |
| 4Use a parameter to pass a value into a function so it does not need to use a variable from outside | Ddef add(): total = 2 + 3 | |
| 5def make(): age = 12 make() print(age) | Eage is local to make(), so print(age) outside the function causes a NameError. Fix: print it inside the function or return it. | |
| 6def show(): print(points) show() | Fpoints was never created, so show() causes a NameError. Fix: create points outside the function first or pass it in as a parameter. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
local variable — A variable created inside a function. It only exists in that function, so using it outside gives a NameError. A variable made outside all functions is global and can be used anywhere.def show():
total = 5
print(total)def add_bonus():
bonus = 10
print(bonus)score = 0
def show():
print(score)def double(num):
print(num * 2)
double(4)def make():
x = 3
return x