Completed
Dictionary — basics
Questions From This Challenge
Q1mcq1 mark
Which of the following correctly creates a dictionary in Python?
d = {'a': 1, 'b': 2} ✓
d = ['a': 1, 'b': 2]
d = ('a': 1, 'b': 2)
d = <a: 1, b: 2>
Q2mcq1 mark
In a Python dictionary, each element is stored as a:
key-value pair ✓
single value
pair of two values with no keys
fixed-position index
Q3mcq1 mark
Which of these correctly accesses the value associated with the key 'name' in the dictionary d?
d['name'] ✓
d.name
d(name)
d->name
Q4mcq1 mark
If a dictionary d already has the key 'age', what happens when you execute d['age'] = 16?
The value for 'age' is updated to 16 ✓
A new separate key 'age' is added alongside the old one
It raises an error since the key already exists
Nothing happens because keys cannot be reassigned
Q5mcq1 mark
Which of the following best describes a requirement for dictionary keys in Python?
Keys must be immutable and unique within the dictionary ✓
Keys must be mutable and can repeat
Keys must always be integers
Keys can be lists
Q6mcq1 mark
If a key does not exist in a dictionary d and you try to access d['roll'], what does Python raise?
KeyError ✓
IndexError
ValueError
TypeError
Q7output1 mark
What is the output of the following code?
student = {"name": "Riya", "age": 16, "grade": "XI"}
print(student)
Correct output:
{'name': 'Riya', 'age': 16, 'grade': 'XI'}Q8output1 mark
What is the output of the following code?
student = {"name": "Aman", "marks": 88}
print(student["marks"])
Correct output:
88Q9output1 mark
What is the output of the following code?
student = {"name": "Kabir", "marks": 75}
student["marks"] = 80
print(student)
Correct output:
{'name': 'Kabir', 'marks': 80}Q10output1 mark
What is the output of the following code?
student = {"name": "Isha"}
student["age"] = 17
print(student)
Correct output:
{'name': 'Isha', 'age': 17}Q11output1 mark
What is the output of the following code?
marks = {"Math": 90, "Science": 85, "English": 78}
for subject in marks:
print(subject)
Correct output:
Math
Science
EnglishQ12output1 mark
What is the output of the following code?
marks = {"Math": 90, "Science": 85}
for subject in marks:
print(subject, marks[subject])
Correct output:
Math 90
Science 85Q13output1 mark
What is the output of the following code?
info = {"roll": 12, "name": "Dev", "attendance": 92.5}
print(info)
Correct output:
{'roll': 12, 'name': 'Dev', 'attendance': 92.5}Q14output1 mark
What is the output of the following code?
d = {"x": 1, "y": 2, "x": 3}
print(d)
Correct output:
{'x': 3, 'y': 2}Q15output1 mark
What is the output of the following code?
d = {"a": 1, "b": 2}
print("a" in d)
print("c" in d)
Correct output:
True
False