Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get the first element of the tuple.
Python
my_tuple = (10, 20, 30) first_element = my_tuple[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using parentheses instead of square brackets for indexing.
Using curly braces or angle brackets which are invalid for indexing.
โ Incorrect
Use square brackets with index 0 to get the first element of a tuple.
2fill in blank
mediumComplete the code to get the last element of the tuple using negative indexing.
Python
my_tuple = ('a', 'b', 'c', 'd') last_element = my_tuple[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using positive index 1 which gives the second element.
Using -4 which gives the first element but is less clear.
โ Incorrect
Negative indexing starts from the end. Index -1 gives the last element.
3fill in blank
hardFix the error in the code to slice the tuple from index 1 to 3 (excluding 3).
Python
my_tuple = (5, 10, 15, 20, 25) slice_part = my_tuple[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using parentheses instead of square brackets for slicing.
Using comma instead of colon inside the brackets.
โ Incorrect
Use square brackets with colon to slice tuples: [start:end].
4fill in blank
hardFill both blanks to get a slice of the tuple from the second element to the end.
Python
my_tuple = ('x', 'y', 'z', 'w') slice_part = my_tuple[1][2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Forgetting the closing bracket.
Using parentheses instead of square brackets.
โ Incorrect
To slice from index 1 to the end, use [1:] with square brackets.
5fill in blank
hardComplete the code to get every second element from the tuple starting at index 0.
Python
my_tuple = (2, 4, 6, 8, 10, 12) slice_part = my_tuple[[1]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Missing the closing bracket.
Using single colon instead of double colon for step.
โ Incorrect
Use [::2] to slice every second element from the start to the end.