Challenge - 5 Problems
Function Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of a 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
Check how default arguments work and how keyword arguments override them.
โ Incorrect
The function greet has a default greeting 'Hello'. Calling greet('Alice') uses the default. Calling greet('Bob', greeting='Hi') overrides the default with 'Hi'.
โ Predict Output
intermediate2:00remaining
Return value of a function with multiple return statements
What is the output of this code?
Python
def check_number(x): if x > 0: return "Positive" elif x == 0: return "Zero" else: return "Negative" print(check_number(-5))
Attempts:
2 left
๐ก Hint
Look at the input value and which condition it satisfies.
โ Incorrect
The input -5 is less than zero, so the function returns 'Negative'.
๐ Syntax
advanced2:00remaining
Identify the syntax error in function definition
Which option contains a syntax error in the function definition?
Attempts:
2 left
๐ก Hint
Check for missing colons in function headers.
โ Incorrect
Option C is missing a colon ':' after the function parameters, causing a syntax error.
โ Predict Output
advanced2:00remaining
Output of a function using *args and **kwargs
What is the output of this code?
Python
def info(*args, **kwargs): return f"Args: {args}, Kwargs: {kwargs}" print(info(1, 2, 3, name='Alice', age=30))
Attempts:
2 left
๐ก Hint
Remember that *args collects positional arguments as a tuple and **kwargs collects keyword arguments as a dictionary.
โ Incorrect
The *args parameter collects positional arguments into a tuple. The **kwargs parameter collects keyword arguments into a dictionary.
๐ง Conceptual
expert3:00remaining
Effect of mutable default arguments in function definitions
What will be the output after running this code?
Python
def append_item(item, lst=[]): lst.append(item) return lst print(append_item(1)) print(append_item(2))
Attempts:
2 left
๐ก Hint
Think about how default mutable arguments behave across multiple function calls.
โ Incorrect
The default list is created once and shared across calls. So the second call appends 2 to the same list that already contains 1.