Challenge - 5 Problems
Argument Order Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of function call with mixed arguments
What is the output of this Python code?
Python
def greet(name, greeting="Hello", punctuation="!"): return f"{greeting}, {name}{punctuation}" print(greet("Alice", punctuation="."))
Attempts:
2 left
๐ก Hint
Remember that positional arguments come before keyword arguments.
โ Incorrect
The function call uses a positional argument for 'name' and a keyword argument for 'punctuation'. The default greeting 'Hello' is used. So the output is 'Hello, Alice.'.
โ Predict Output
intermediate2:00remaining
Error from wrong argument order
What error does this code produce?
Python
def add(x, y=5, z): return x + y + z add(1, 2, 3)
Attempts:
2 left
๐ก Hint
Check the order of parameters with and without default values.
โ Incorrect
In Python, parameters with default values must come after parameters without defaults. Here, 'z' has no default but comes after 'y' which has a default, causing a SyntaxError.
โ Predict Output
advanced2:00remaining
Output with *args and keyword-only arguments
What is the output of this code?
Python
def func(a, b, *args, c=10, d=20): return a + b + sum(args) + c + d print(func(1, 2, 3, 4, c=5))
Attempts:
2 left
๐ก Hint
Remember that after *args, parameters are keyword-only.
โ Incorrect
Arguments: a=1, b=2, args=(3,4), c=5 (keyword), d=20 (default). Sum is 1+2+3+4+5+20=35.
โ Predict Output
advanced2:00remaining
Output with positional-only and keyword-only arguments
What is the output of this code?
Python
def example(a, /, b, *, c): return a + b + c print(example(1, 2, c=3))
Attempts:
2 left
๐ก Hint
Positional-only arguments must be passed positionally, keyword-only must be passed by name.
โ Incorrect
a=1 (positional-only), b=2 (positional or keyword), c=3 (keyword-only). Sum is 1+2+3=6.
๐ง Conceptual
expert2:00remaining
Identify the invalid function definition
Which of these function definitions is invalid due to argument order rules?
Attempts:
2 left
๐ก Hint
Parameters with default values must come after those without defaults.
โ Incorrect
Option B has a parameter 'a' with default before 'b' without default, which is invalid syntax in Python.