Challenge - 5 Problems
Multiple Return Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
What is the output of this function returning multiple values?
Consider this Python function that returns multiple values. What will be printed when calling
result = func() and then print(result)?Python
def func(): return 1, 2, 3 result = func() print(result)
Attempts:
2 left
๐ก Hint
Remember that returning multiple values in Python actually returns a tuple.
โ Incorrect
In Python, when you return multiple values separated by commas, it returns a tuple containing those values. So the output is the tuple (1, 2, 3).
โ Predict Output
intermediate2:00remaining
What is the value of variables after unpacking multiple return values?
Given this code, what are the values of
a, b, and c after execution?Python
def get_values(): return 10, 20, 30 a, b, c = get_values()
Attempts:
2 left
๐ก Hint
Check how many values the function returns and how many variables are on the left side.
โ Incorrect
The function returns three values, and there are three variables to receive them. So a=10, b=20, c=30.
โ Predict Output
advanced2:00remaining
What is the output when returning multiple values with a conditional expression?
What will this code print?
Python
def check(num): return (num, 'even') if num % 2 == 0 else (num, 'odd') print(check(7))
Attempts:
2 left
๐ก Hint
Look at the condition and what tuple is returned for odd numbers.
โ Incorrect
Since 7 is odd, the else part returns (7, 'odd'), so that tuple is printed.
โ Predict Output
advanced2:00remaining
What error occurs when unpacking fewer variables than returned?
What happens when you run this code?
Python
def data(): return 1, 2, 3 x, y = data()
Attempts:
2 left
๐ก Hint
Check how many values are returned vs how many variables are on the left.
โ Incorrect
The function returns 3 values but only 2 variables are provided, so Python raises a ValueError.
๐ง Conceptual
expert2:00remaining
How does Python handle multiple return values internally?
When a Python function returns multiple values separated by commas, what is actually returned?
Attempts:
2 left
๐ก Hint
Think about what data structure groups multiple values in Python without keys.
โ Incorrect
Python packs multiple return values into a tuple automatically, which is why you can unpack them easily.