Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove the last element from the list.
DSA Python
arr = [1, 2, 3, 4, 5] arr.[1]() print(arr)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove() which needs a value, not an index.
Using clear() which empties the whole list.
✗ Incorrect
The pop() method removes the last item from the list.
2fill in blank
mediumComplete the code to delete the last element using the del statement.
DSA Python
arr = [10, 20, 30, 40] del arr[1] print(arr)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive indices which delete the first or wrong element.
Using slice notation which deletes multiple elements.
✗ Incorrect
Using del arr[-1] deletes the last element by index.
3fill in blank
hardFix the error in the code to remove the last element safely.
DSA Python
arr = [] if arr: arr.[1]() print(arr)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove() which needs a value and causes error if list is empty.
Using clear() which empties the whole list.
✗ Incorrect
Using pop() inside a check ensures no error if the list is empty.
4fill in blank
hardFill both blanks to remove the last element and print it.
DSA Python
arr = [5, 6, 7] last = arr[1]() print([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the list instead of the removed element.
Using remove() which needs a value.
✗ Incorrect
pop() removes and returns the last element, which is stored in last.
5fill in blank
hardFill all three blanks to remove the last element by index and print the updated list.
DSA Python
arr = [9, 8, 7, 6] index = [1] removed = arr.[2](index) print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove() which needs a value, not an index.
Printing the removed element instead of the updated list.
✗ Incorrect
Using pop(-1) removes the last element by index and returns it. Printing arr shows the updated list.