Question 12: Mastering Dictionary Manipulation

This quiz question focuses on dictionary manipulation in Python, including how to access, modify, and handle dictionary keys and values.

You should understand how to iterate over dictionaries and use dictionary methods effectively.

Question: Dictionary Manipulation

Consider the following dictionary students that contains student names as keys and their corresponding grades as values:

students = {
    "Alice": 85,
    "Bob": 92,
    "Charlie": 78,
    "David": 90,
    "Eve": 88
}

Which of the following code snippets will generate a new dictionary containing only those students who scored 85 or higher, with their names as keys and their grades increased by 5 as values?















Option A is the correct answer.

  • Explanation: Correctly uses a dictionary comprehension to filter students who scored 85 or higher and increases their grades by 5.
  • Result: {'Alice': 90, 'Bob': 97, 'David': 95, 'Eve': 93}
  • Reason for Correctness: It directly constructs the desired dictionary with both conditions applied in a single step.

Leave a Reply