Question 1
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
undo_stack = ["type A"]
undo_stack.pop()
undo_stack.pop()
print("Undone twice")
- A ValueError: "type A" not in list
- B It prints Undone twice
- C TypeError: pop() needs an index
- D IndexError: the second pop() runs on an empty list; check if undo_stack: first Correct
Correct Answer: Option D
pop() needs at least one item. Guard it with if undo_stack:.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!