Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the element at index 2 in the list.
DSA Python
my_list = [10, 20, 30, 40, 50] print(my_list[[1]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 instead of 2, which accesses the fourth element.
Using index 1, which accesses the second element.
✗ Incorrect
Index 2 accesses the third element in the list, which is 30.
2fill in blank
mediumComplete the code to update the element at index 1 to 99.
DSA Python
numbers = [5, 10, 15, 20] numbers[[1]] = 99 print(numbers)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Updating index 0 instead of 1.
Using an index out of range.
✗ Incorrect
Index 1 refers to the second element, which is updated to 99.
3fill in blank
hardFix the error in the code to correctly update the last element to 100.
DSA Python
data = [1, 2, 3, 4, 5] data[[1]] = 100 print(data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 5 which is out of range.
Using index -1 when positive index is expected.
✗ Incorrect
The last element is at index 4 (length - 1), so data[4] updates it correctly.
4fill in blank
hardFill both blanks to access and update the middle element of the list.
DSA Python
arr = [10, 20, 30, 40, 50] mid_index = len(arr) [1] 2 arr[mid_index] = [2] print(arr)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' which results in float index causing error.
Updating the middle element to wrong value.
✗ Incorrect
Using integer division '//' by 2 finds the middle index. Updating that index to 25 changes the middle element.
5fill in blank
hardFill all three blanks to create a dictionary with keys as uppercase letters and values as elements greater than 10.
DSA Python
values = {'a': 5, 'b': 15, 'c': 25, 'd': 8}
result = { [1]: [2] for k, v in values.items() if v [3] 10}
print(result) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' for keys.
Using '<' instead of '>' in the condition.
Using keys as values or vice versa.
✗ Incorrect
Keys are converted to uppercase with k.upper(), values are v, and only values greater than 10 are included.