Challenge - 5 Problems
Tuple Slicing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of tuple slicing with negative indices
What is the output of this Python code?
Python
t = (10, 20, 30, 40, 50, 60) print(t[-4:-1])
Attempts:
2 left
๐ก Hint
Remember that slicing excludes the end index and negative indices count from the end.
โ Incorrect
The slice t[-4:-1] starts at index -4 (which is 30) and goes up to but not including index -1 (which is 60). So it includes 30, 40, and 50.
โ Predict Output
intermediate2:00remaining
Result of tuple indexing with nested tuples
What will be printed by this code?
Python
t = (1, (2, 3), 4, (5, 6, 7)) print(t[3][1])
Attempts:
2 left
๐ก Hint
First index selects the nested tuple, second index selects element inside it.
โ Incorrect
t[3] is the tuple (5, 6, 7). Index 1 of that tuple is 6.
โ Predict Output
advanced2:00remaining
Output of tuple slicing with step and negative step
What is the output of this code?
Python
t = (0, 1, 2, 3, 4, 5, 6) print(t[5:1:-2])
Attempts:
2 left
๐ก Hint
Slicing with a negative step goes backwards and excludes the end index.
โ Incorrect
t[5:1:-2] starts at index 5 (value 5), goes down to index 2 (since end is 1 but excluded), stepping by -2, so picks 5 and then 3.
โ Predict Output
advanced2:00remaining
Value of variable after tuple slicing and concatenation
What is the value of variable result after running this code?
Python
t = (1, 2, 3, 4, 5) result = t[:2] + t[-2:] print(result)
Attempts:
2 left
๐ก Hint
Slicing t[:2] gets first two elements, t[-2:] gets last two elements, then they are joined.
โ Incorrect
t[:2] is (1, 2), t[-2:] is (4, 5), concatenated gives (1, 2, 4, 5).
โ Predict Output
expert2:00remaining
Output of complex tuple slicing with omitted indices
What does this code print?
Python
t = (10, 20, 30, 40, 50, 60, 70) print(t[::3][1:])
Attempts:
2 left
๐ก Hint
First slice picks every 3rd element, second slice takes from index 1 to end.
โ Incorrect
t[::3] is (10, 40, 70). Then [1:] slices from index 1 to end, so (40, 70).