Challenge - 5 Problems
Parameter Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of function with default and keyword arguments
What is the output of this Python code?
Python
def greet(name, greeting="Hello"): return f"{greeting}, {name}!" print(greet("Alice")) print(greet("Bob", greeting="Hi"))
Attempts:
2 left
๐ก Hint
Remember the default value is used if no argument is given for that parameter.
โ Incorrect
The function greet has a default value for greeting. When called with only one argument, greeting uses its default 'Hello'. When called with greeting='Hi', it uses the provided value.
โ Predict Output
intermediate2:00remaining
Output with *args and **kwargs parameters
What will this code print?
Python
def show_args(*args, **kwargs): print(f"Positional: {args}") print(f"Keyword: {kwargs}") show_args(1, 2, a=3, b=4)
Attempts:
2 left
๐ก Hint
*args collects positional arguments as a tuple, **kwargs collects keyword arguments as a dictionary.
โ Incorrect
The *args parameter collects all positional arguments into a tuple. The **kwargs parameter collects all keyword arguments into a dictionary.
โ Predict Output
advanced2:00remaining
Output of function with mutable default argument
What is the output of this code?
Python
def add_item(item, item_list=[]): item_list.append(item) return item_list print(add_item('apple')) print(add_item('banana'))
Attempts:
2 left
๐ก Hint
Default arguments are evaluated once when the function is defined, not each time it is called.
โ Incorrect
The default list is shared across calls, so the second call appends 'banana' to the same list that already contains 'apple'.
โ Predict Output
advanced2:00remaining
Output of function with positional-only and keyword-only parameters
What will this code print?
Python
def func(a, /, b, *, c): return a + b + c print(func(1, 2, c=3))
Attempts:
2 left
๐ก Hint
Parameters before / are positional-only, parameters after * are keyword-only.
โ Incorrect
Parameter 'a' is positional-only, so it must be passed positionally. 'b' is positional or keyword, 'c' is keyword-only. The call matches these rules.
๐ง Conceptual
expert2:00remaining
Identify the error in function call with argument unpacking
Given the function definition below, which option will cause a TypeError when called?
Python
def combine(a, b, c): return a + b + c
Attempts:
2 left
๐ก Hint
Check if any argument is passed twice due to unpacking and explicit argument.
โ Incorrect
Option A passes 'c' twice: once in kwargs and once explicitly, causing TypeError: multiple values for argument 'c'.