PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
A developer wants to create a dictionary that maps employee IDs to their department names. The IDs are integers, and departments are strings. Which of the following correctly creates such a dictionary?
⚠ Common exam trap
Candidates often confuse dictionary literal syntax with the dict() constructor's keyword argument syntax, or misusing the dict() constructor with multiple arguments.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
employees = {101: "HR", 102: "IT"}
The dictionary literal {101: "HR", 102: "IT"} is the correct syntax for creating a dictionary with integer keys and string values. The dict() constructor can also be used, but keyword arguments cannot have integer names, and passing multiple positional arguments is invalid. The literal syntax is straightforward and commonly used for this purpose.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
employees = {101: "HR", 102: "IT"}
Why this is correct
This uses a dictionary literal with integer keys and string values. The syntax {key: value, ...} is the standard way to create a dictionary. It correctly maps employee IDs (101 and 102) to department names ("HR" and "IT"). This is valid and creates the desired dictionary.
- ✗
employees = dict(101: "HR", 102: "IT")
Why it's wrong here
This syntax is invalid. The dict() constructor does not accept colon-separated key-value pairs as arguments. Colons are used in dictionary literals, not in function calls. Attempting to run this will result in a SyntaxError. The correct way to use dict() with integer keys is to pass an iterable of pairs, such as dict([(101, "HR"), (102, "IT")]).
- ✗
employees = dict(101="HR", 102="IT")
Why it's wrong here
The dict() constructor with keyword arguments requires keys to be valid Python identifiers, which cannot be numbers. Using 101="HR" is a syntax error because keyword argument names must be strings that are valid identifiers. Therefore, this code will not run. To create a dictionary with integer keys, use a dictionary literal or a list of key-value pairs.
- ✗
employees = dict([101, "HR"], [102, "IT"])
Why it's wrong here
The dict() constructor can accept an iterable of key-value pairs, but each pair must be a sequence of two elements. Here, dict([101, "HR"], [102, "IT"]) passes two arguments, each a list of two elements. However, the dict() constructor expects a single iterable argument, not multiple positional arguments. This will raise a TypeError. The correct form would be dict([[101, "HR"], [102, "IT"]]) or dict(((101, "HR"), (102, "IT"))).
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.