Question 5
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
cart = {"book": 450, "pen": 20}
print("Total:", sum(cart))
- A TypeError: iterating a dict gives its keys (strings), so sum() tries 0 + "book"; use sum(cart.values()) Correct
- B It prints Total: 470
- C KeyError: book
- D ValueError
Correct Answer: Option A
Anything that iterates a dict sees the keys unless you ask for values() or items().
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!