Challenge - 5 Problems
Master of Multiple Parameters
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of function with multiple parameters and default values
What is the output of this Python code?
Python
def greet(name, greeting="Hello", punctuation="!"): return f"{greeting}, {name}{punctuation}" result = greet("Alice", punctuation=".") print(result)
Attempts:
2 left
๐ก Hint
Check which parameters have default values and how they are overridden.
โ Incorrect
The function greet has three parameters: name (required), greeting (default "Hello"), and punctuation (default "!"). The call greet("Alice", punctuation=".") uses the default greeting but overrides punctuation with ".". So the output is "Hello, Alice.".
โ Predict Output
intermediate2:00remaining
Output of function with *args and multiple parameters
What will this code print?
Python
def add_numbers(a, b, *args): total = a + b for num in args: total += num return total print(add_numbers(1, 2, 3, 4))
Attempts:
2 left
๐ก Hint
Remember *args collects extra positional arguments as a tuple.
โ Incorrect
The function adds a and b first (1 + 2 = 3), then adds each number in args (3 and 4), total is 10.
โ Predict Output
advanced2:00remaining
Output of function with keyword-only parameters
What is the output of this code?
Python
def describe_pet(name, *, species="dog", age=1): return f"{name} is a {age}-year-old {species}." print(describe_pet("Buddy", species="cat"))
Attempts:
2 left
๐ก Hint
Parameters after * must be passed as keywords.
โ Incorrect
species and age are keyword-only parameters with defaults. species is overridden to "cat", age remains 1.
โ Predict Output
advanced2:00remaining
Output of function with multiple parameters and unpacking
What does this code print?
Python
def multiply(x, y, z): return x * y * z values = (2, 3, 4) print(multiply(*values))
Attempts:
2 left
๐ก Hint
The * operator unpacks the tuple into separate arguments.
โ Incorrect
The tuple (2,3,4) is unpacked as multiply(2,3,4), so 2*3*4=24.
๐ง Conceptual
expert3:00remaining
Understanding parameter passing with mutable default arguments
Consider this function definition:
def append_item(item, items=[]):
items.append(item)
return items
What will be the output of these two calls?
print(append_item(1))
print(append_item(2))
Attempts:
2 left
๐ก Hint
Default mutable arguments keep their state between calls.
โ Incorrect
The default list is created once. The first call appends 1, returning [1]. The second call appends 2 to the same list, returning [1, 2].