Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free Python Institute PCEP - Certified Entry-Level Python Programmer PCEP-30-02 Exam Questions

Last updated: · 14 practice questions with answers and explanations

Page: 1 / 5 Total 30 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Computer Programming Fundamentals

Skill tested: Evaluates Python assignment, object identity, and mutable list aliasing.

A reporting script initializes `primary = [4, 7]` and then assigns `backup = primary`. A later operation executes `backup += [9]`, after which the script prints both variables. The developer expected `backup` to contain the added value while leaving `primary` unchanged, because the operation looks like a reassignment. The script must retain the original list independently for a later comparison, and the developer wants the smallest code change that makes the intended behavior reliable. Which change should be made before modifying `backup`?

Correct Answer: C. Assign `backup = primary.copy()` so that `backup` refers to a separate list.
Explanation:

The initial assignment makes both names refer to the same mutable list. Augmented assignment with a list extends that list in place, so both names observe the change. A shallow copy using `primary.copy()` creates an independent list, which is sufficient here because the elements are integers. Replacing `+=` with `+` would create a new list at that later step, but the original shared reference already exists and the code's intended independence is clearer and reliable when the copy is made. Tuples cannot be extended in place, and comments do not change runtime behavior.

Question 2

New Single answer

Topic: Computer Programming Fundamentals

Skill tested: Assesses evaluation of Python Boolean expressions and operator precedence.

A command-line utility accepts a numeric status code and a Boolean flag indicating whether the user has administrative access. A report should be generated when the status is either 200 or 201, but only for an administrator. A developer writes `if status == 200 or status == 201 and is_admin:` and observes that a non-administrator with status 200 still receives the report. The team wants to preserve the stated policy without relying on readers to infer precedence. Which condition expresses the requirement correctly?

Correct Answer: C. `if (status == 200 or status == 201) and is_admin:`
Explanation:

Python evaluates `and` before `or`, so the original condition means `status == 200 or (status == 201 and is_admin)`. That permits status 200 regardless of the flag. Parentheses make the accepted status alternatives one condition, which is then combined with the administrator requirement. The two equality checks in C cannot both be true for a single integer status. In D, `(200 or 201)` evaluates to 200 because 200 is truthy, so it does not test both permitted codes.

Question 3

New Single answer

Topic: Control Flow

Skill tested: Evaluates loop control and correct use of `continue` in a processing loop.

A data-import routine processes a list of records in order. Invalid records should be skipped, while each valid record should be normalized and appended to an output list. During a refactor, a developer adds a validation branch inside a `for` loop but uses a control statement that stops the loop as soon as it encounters an invalid record. Valid records later in the input are therefore lost. The input order must remain unchanged, and the routine should not terminate early. Which control-flow change best meets the requirement?

Correct Answer: B. Replace the early `break` with `continue` in the invalid-record branch.
Explanation:

`break` exits the nearest loop, so it prevents later records from being examined. `continue` skips the remainder of the current iteration and begins the next one, preserving order while allowing subsequent valid records to be processed. `pass` does nothing and would allow the invalid record to reach later processing unless additional structure prevented that. Switching loop types does not itself fix the control-flow error, and validating after appending risks adding invalid data.

Question 4

New Single answer

Topic: Control Flow

Skill tested: Assesses `range` boundaries and loop iteration counts.

A maintenance script must inspect records numbered from 1 through a configured limit, inclusive. The limit is stored in `limit`, and the script currently uses `for record_number in range(1, limit):`. Testing shows that the final record is never inspected. The team wants to keep a `for` loop and avoid adding a special-case iteration after the loop. Which loop header correctly visits every required record when `limit` is a positive integer?

Correct Answer: A. `for record_number in range(1, limit + 1):`
Explanation:

The stop value supplied to `range` is exclusive. `range(1, limit)` produces values from 1 through `limit - 1`, so adding one to the stop value includes the configured limit. Starting at zero includes an unwanted value and still excludes the limit. Subtracting one shortens the iteration further. With the default positive step, a range beginning at `limit` and stopping at 1 is empty because it cannot move toward the stop value.

Question 5

New Single answer

Topic: Data Collections

Skill tested: Evaluates list slicing, negative indices, and slice stop semantics.

A small audit tool stores the five most recent event codes in chronological order in a list named `events`. The report must display the three newest codes, also in chronological order, without changing the original list. The tool must work for any list containing at least three events; the event codes are not guaranteed to be unique. Which expression produces the required result?

Correct Answer: C. `events[-3:]`
Explanation:

The slice `events[-3:]` starts at the third element from the end and continues to the end, returning the newest three events in their existing chronological order. Slicing creates a new list, so the source is not modified. The stop index in `events[-3:-1]` is excluded, leaving only two elements. `events[:3]` selects the oldest entries. Calling `reverse()` mutates the original list and then selects values in reverse chronological order, violating both constraints.

Question 6

New Single answer

Topic: Data Collections

Skill tested: Assesses safe dictionary lookup and handling of absent keys.

A monitoring program aggregates counts by service name in a dictionary named `counts`. Some service names have not appeared yet, so they are absent from the dictionary. When processing each event, the program must increment that service's count, initializing it to one on its first occurrence. The code must not raise `KeyError`, and it should avoid a separate membership test followed by a second lookup. Which statement is the most appropriate?

Correct Answer: C. `counts[name] = counts.get(name, 0) + 1`
Explanation:

`dict.get(name, 0)` returns the stored count when the key exists and zero otherwise; assigning the result plus one back to the key handles both cases without a membership test. Direct indexing in B raises `KeyError` for a new service. `setdefault` is a method call that returns a value, and Python does not allow assignment augmented by `+=` to that call result; moreover, setting a missing key to one and incrementing it would require a different expression. `get` itself does not modify the dictionary, so D is not a valid assignment target.

Question 7

New Multiple answers

Topic: Data Collections

Skill tested: Evaluates list-comprehension filtering and string transformation.

A deployment team receives a list of environment labels that may contain surrounding whitespace and mixed capitalization. It needs a new list containing lowercase labels, with surrounding whitespace removed, while excluding labels that become empty after trimming. The original input list must remain unchanged because another report uses it. Select TWO expressions that meet all requirements. Select two answers.

Correct Answer: B. `[label.lower().strip() for label in labels if label.strip()]`; E. `[label.strip().lower() for label in labels if label.strip()]`
Explanation:

Both A and B build a new list, trim surrounding whitespace, convert retained strings to lowercase, and test the trimmed value so whitespace-only labels are excluded. Applying `lower()` before or after `strip()` produces the same result for these operations. C tests the untrimmed string, so a whitespace-only value passes the filter and becomes an empty string. D replaces the contents of the original list through slice assignment. E filters using a lowercased value but returns only the stripped, not lowercased, label.

Question 8

New Single answer

Topic: Functions and Exceptions

Skill tested: Assesses local and global variable scope during function execution.

A script keeps a module-level counter initialized to zero. A function named `record_event()` contains the statement `counter += 1`, and calling it raises `UnboundLocalError`. The intended behavior is to update the module-level integer each time the function runs; the function does not need to return a new counter value, and the team wants to retain the existing interface. Which change directly resolves the scope issue?

Correct Answer: B. Add `global counter` inside `record_event()` before the augmented assignment.
Explanation:

An assignment anywhere in a function makes that name local by default. The augmented assignment reads the local value before updating it, but no local value has been assigned, producing `UnboundLocalError`. Declaring `global counter` tells Python to bind the assignment to the module-level name. `nonlocal` applies to a binding in an enclosing function scope, not the module scope. Rewriting the assignment does not change the scope rule, and `self` is only meaningful as an explicit instance attribute reference.

Question 9

New Single answer

Topic: Functions and Exceptions

Skill tested: Evaluates exception handling for invalid input and precise exception selection.

A utility converts a user-supplied string to an integer and then uses the result as a list index. A malformed string should be reported as an input error, but an unrelated programming error elsewhere in the routine should not be hidden. The current code catches `Exception`, which makes debugging difficult. Which exception should the conversion-specific handler catch?

Correct Answer: B. `ValueError`
Explanation:

Converting a string such as `"abc"` with `int()` raises `ValueError`, so catching that exception around the conversion handles the intended malformed-input case precisely. `TypeError` applies when an operation receives an object of an inappropriate type, such as passing an incompatible object to `int()`. `IndexError` can arise later if the resulting integer is outside the list bounds, but it does not describe failed integer conversion. Catching `Exception` is overly broad and can conceal unrelated defects.

Question 10

New Single answer

Topic: Functions and Exceptions

Skill tested: Assesses recursive function base cases and termination.

A team writes a recursive function to compute the sum of the integers from 1 through `n`, where `n` is a non-negative integer. The function currently calls itself with `n - 1` but never returns a value for `n == 0`, so it eventually exceeds the recursion limit. The intended result for zero is zero, and negative inputs are outside the function's contract. Which base-case behavior should be added?

Correct Answer: C. Return `0` when `n == 0`.
Explanation:

A recursive definition needs a terminating base case. Returning zero at `n == 0` matches the specified sum and allows each earlier call to add its current value while unwinding. Calling again with the same value never makes progress. Returning `n - 1` yields -1 at the base case and makes the computed sum incorrect. Raising `RecursionError` deliberately reproduces the failure rather than implementing the function's contract.

Question 11

New Multiple answers

Topic: Configuration Management

Skill tested: Evaluates page-layout and task time-entry customization decisions.

An operations administrator is configuring a project workspace for two personas. Field technicians need a compact task page that exposes only the fields they use, while project analysts need a separate page layout with additional reporting fields. The organization also requires technicians to enter time against tasks, but it does not want to change how analysts enter time. The available configuration includes persona-specific page layouts and a Task Time Entry Mode setting. Select TWO actions that satisfy the requirements without imposing the technician workflow on analysts. Select two answers.

Correct Answer: D. Create and assign an appropriate page layout for each persona.; E. Configure Task Time Entry Mode for the technician persona using the applicable user or persona configuration.
Explanation:

Separate page layouts let each persona see the task fields appropriate to its work. Configuring Task Time Entry Mode at the applicable technician scope meets the time-entry requirement without changing the analyst workflow. A global setting would violate the stated separation if it applies to both groups. A single layout cannot provide the requested tailored pages merely through naming conventions, and report folders organize reports rather than control task-page fields. These choices use only the configuration areas named in the objective without assuming unrelated access behavior.

Question 12

New Single answer

Topic: Configuration Management

Skill tested: Assesses report and dashboard folder organization for controlled discoverability.

A project office publishes a set of operational reports and dashboards for team leads. Analysts also maintain draft assets that should not appear alongside the approved material, and users need to find the published content consistently. The administrator wants to organize the assets using report and dashboard folders rather than changing the reports' data logic. Which approach best meets the requirement?

Correct Answer: D. Create distinct folders for approved shared content and analyst drafts, then place each asset in the appropriate folder.
Explanation:

Separate, clearly named folders organize published reports and dashboards independently from draft assets, improving discoverability without altering report logic. A naming prefix in one folder does not provide the requested organizational separation. Duplicating reports for each lead adds maintenance and still relies on bookmarks rather than a shared structure. Task page layouts govern page presentation, not report and dashboard organization.

Question 13

New Single answer

Topic: Automated Jobs & Scheduled Maintenance

Skill tested: Assesses review and removal of obsolete scheduled jobs.

During a monthly operations review, an administrator finds a scheduled automated job whose owner has left the organization. The job has no documented business purpose, has produced repeated failures, and is not referenced by a current operational runbook. The team must reduce unnecessary scheduled activity while avoiding disruption to supported processes. What should the administrator do first?

Correct Answer: D. Review the job's schedule, purpose, ownership, and dependencies with the responsible operational stakeholders before deleting it.
Explanation:

Scheduled-job maintenance should establish whether a job is still required and identify dependencies before removal. The missing owner and failures are strong reasons to investigate, but they do not prove that no process depends on it. Immediate deletion may disrupt a supported process; duplicating an undocumented job can create duplicate execution, and disabling every job unnecessarily affects unrelated operations. After stakeholder review confirms that the job is obsolete, it can be safely removed through the established maintenance process.

Question 14

New Single answer

Topic: Automated Jobs & Scheduled Maintenance

Skill tested: Evaluates configuration of Actuals Configuration Group calculation modes.

A finance administrator is reviewing actuals processing for a project system. One Actuals Configuration Group is intended to recalculate values automatically as relevant records change; another is designed for a controlled batch calculation during a maintenance window. The administrator must preserve these distinct operating requirements rather than applying one mode universally. Which approach is most appropriate?

Correct Answer: B. Configure the calculation mode separately for each Actuals Configuration Group to match its operational requirement.
Explanation:

Calculation mode is part of the Actuals Configuration Group setup, so each group should be configured according to its intended processing behavior. The scenario explicitly requires one group to recalculate automatically and another to run in a controlled batch window; a single mode for both would fail one requirement. App-log maintenance is a separate operational concern and does not configure or trigger actuals calculations. The administrator should also verify the resulting schedules and behavior during routine review.