Challenge - 5 Problems
Tuple Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of tuple creation with single element
What is the output of this code?
t = (5) print(type(t))
Python
t = (5) print(type(t))
Attempts:
2 left
๐ก Hint
Remember that parentheses alone do not create a tuple unless there is a comma.
โ Incorrect
Parentheses around a single value without a comma do not create a tuple. So (5) is just the integer 5 in parentheses, not a tuple.
โ Predict Output
intermediate2:00remaining
Creating a tuple with one element
What is the output of this code?
t = (5,) print(type(t))
Python
t = (5,) print(type(t))
Attempts:
2 left
๐ก Hint
Check the comma after the element inside parentheses.
โ Incorrect
A comma after a single element inside parentheses creates a tuple with one element.
โ Predict Output
advanced2:00remaining
Output of tuple unpacking with multiple elements
What is the output of this code?
a, b, c = (1, 2, 3) print(a + b + c)
Python
a, b, c = (1, 2, 3) print(a + b + c)
Attempts:
2 left
๐ก Hint
Unpacking assigns each tuple element to a variable.
โ Incorrect
The tuple elements 1, 2, 3 are assigned to a, b, c respectively. Their sum is 6.
โ Predict Output
advanced2:00remaining
Output of tuple creation without parentheses
What is the output of this code?
t = 1, 2, 3 print(type(t))
Python
t = 1, 2, 3 print(type(t))
Attempts:
2 left
๐ก Hint
Parentheses are optional when creating tuples with multiple elements.
โ Incorrect
Comma-separated values without parentheses create a tuple by default.
โ Predict Output
expert3:00remaining
Output of nested tuple unpacking
What is the output of this code?
t = (1, (2, 3), 4) a, (b, c), d = t print(b * c + a + d)
Python
t = (1, (2, 3), 4) a, (b, c), d = t print(b * c + a + d)
Attempts:
2 left
๐ก Hint
Unpack the nested tuple carefully and then do the math.
โ Incorrect
a=1, b=2, c=3, d=4; calculation is 2*3 + 1 + 4 = 6 + 1 + 4 = 11.