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 func(): x = 10 print(x) | AOutput: Hi | |
| 2count = 0 def add_one(): count += 1 | BError: Can't modify global without 'global' | |
| 3x = 5 def show(): print(x) show() | COk: 'global' lets you modify it | |
| 4count = 0 def add(): global count count += 1 | DOutput: NameError | |
| 5def func(): y = 99 func() print(y) | EError: x is local, not visible outside | |
| 6msg = 'Hi' def greet(): print(msg) greet() | FValid: Read global inside function |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Scope — Where a variable can be accessed - local or global.~~Local variabledef func():
x = 5
# x is a local variablex = 10
# x is a global variable
def func():
print(x)def func():
y = 5
func()
print(y)
# causes NameErrorx = 'outside'
def func():
x = 'inside'
print(x)
# prints 'inside'def add(a, b):
result = a + b
return result