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 greet(greeting='Hi', name): pass | AError: Missing required 'base' | |
| 2def power(base, exp=2): return base ** exp power(exp=3) | BError: Default args must come last | |
| 3def greet(name='World'): print('Hi ' + name) | COutput: Hi World | |
| 4def power(n, exp=2): return n ** exp | DOutput: Hi Alice | |
| 5def hi(name='World'): print('Hi', name) hi() | EOk: exp defaults to 2 | |
| 6def hi(name='World'): print('Hi', name) hi('Alice') | FValid: name is optional |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Default argument — A pre-set value used when no argument is provided.~~Optional parameterdef greet(name='World'):
print('Hi ' + name)def power(base, exp=2):
return base ** expdef repeat(msg, times=3):
for i in range(times):
print(msg)def greet(name='World'):
print('Hi ' + name)
greet('Alice')def func(a, b=5, c=10):
return a + b + c