Dictionaries & Sets · Question 13 · Medium

A loop over items() adds up only the marks above 70. What total is printed?

marks = {"Arjun": 71, "Divya": 88, "Farhan": 64}
total = 0
for name, m in marks.items():
    if m > 70:
        total += m
print(total)
  1. 223
  2. 88
  3. 152
  4. 159
Answer and explanation

Answer: D. 159

Explanation: items() gives each key with its value. 71 and 88 are above 70, while 64 is not, so the total is 71 + 88 = 159.

Previous: A dictionary comprehension maps numbers to their squares. What is printed? · Next: Which of the following values can be used as a dictionary key?

Practise dictionaries & sets

Try a fresh set of dictionaries & sets questions with an explanation after every answer, free and without signing up: Dictionaries & Sets practice. Or sit a full placement mock test.

More dictionaries & sets questions

More python practice

Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge