0
0
Pythonprogramming~20 mins

Tuple creation in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Tuple Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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))
A<class 'list'>
B<class 'int'>
CSyntaxError
D<class 'tuple'>
Attempts:
2 left
๐Ÿ’ก Hint
Remember that parentheses alone do not create a tuple unless there is a comma.
โ“ Predict Output
intermediate
2: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))
A<class 'int'>
BSyntaxError
C<class 'tuple'>
D<class 'list'>
Attempts:
2 left
๐Ÿ’ก Hint
Check the comma after the element inside parentheses.
โ“ Predict Output
advanced
2: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)
A6
B123
CTypeError
DSyntaxError
Attempts:
2 left
๐Ÿ’ก Hint
Unpacking assigns each tuple element to a variable.
โ“ Predict Output
advanced
2: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))
A<class 'tuple'>
B<class 'list'>
C<class 'int'>
DSyntaxError
Attempts:
2 left
๐Ÿ’ก Hint
Parentheses are optional when creating tuples with multiple elements.
โ“ Predict Output
expert
3: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)
ATypeError
B10
CSyntaxError
D11
Attempts:
2 left
๐Ÿ’ก Hint
Unpack the nested tuple carefully and then do the math.