Certified Associate in Python Programming (PCAP) — Question 137
You need data which can act as a simple telephone directory. You can obtain it with the following clauses (Choose two.) (assume that no other items have been created before)
Answer options
- A. dir={'Mom': 5551234567, 'Dad': 5557654321}
- B. dir= {'Mom': '5551234567', 'Dad': '5557654321'}
- C. dir= {Mom: 5551234567, Dad: 5557654321}
- D. dir= {Mom: '5551234567', Dad: '5557654321'}
Correct answer: A, B
Explanation
The correct options A and B both use valid syntax for creating a dictionary in Python, with A using integers for phone numbers and B using strings. Options C and D are incorrect because they do not enclose the keys 'Mom' and 'Dad' in quotes, which is necessary for string literals in Python.