Courseiva
Back to Certified Entry-Level Python Programmer PCEP questions

Scenario-based practice

Hard Difficulty Questions

Practise Certified Entry-Level Python Programmer PCEP practice questions — original exam-style scenarios covering every exam domain, with detailed explanations, wrong-answer analysis, and common exam traps.

18
scenario questions
PCEP
exam code
Python Institute
vendor

Scenario guide

How to approach hard difficulty questions

These are the questions most candidates get wrong. They require connecting multiple concepts, reading tricky output, or knowing edge-case behaviour that isn't on most study cards. Practising them trains you to operate under uncertainty — a necessary skill on the real exam.

Quick answer

Hard Difficulty Questions questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Related practice questions

Related PCEP topic practice pages

Scenario questions usually connect to one or more exam topics. Use these links to review the underlying concepts behind the scenario.

Practice set

Practice scenarios

Question 1hardmultiple choice
Full question →

Refer to the exhibit. What is the printed value?

Exhibit

Refer to the exhibit.

```python
x = 5
y = 2
z = x ** y + x % y * 2
print(z)
```

You are a developer in a financial firm. Your team is building a Python module that performs complex calculations on large datasets. To improve performance, you are using list comprehensions and built-in functions. Your code passes all unit tests, but during integration testing, the memory usage spikes unexpectedly. The problematic area is a function that constructs a large list of intermediate results using a list comprehension that references a generator. The code is:

def process(data):

results = [expensive_transform(x) for x in data]

# further processing on results

You suspect that the list comprehension stores all results in memory at once, but you need to keep the function's output as a list for subsequent operations. What is the best solution to reduce memory without changing the function's return type?

Question 3hardmultiple choice
Full question →

Refer to the exhibit. What is the output of the code?

Exhibit

>>> my_list = [1, 2, 3, 4, 5]
>>> for i in range(len(my_list)):
...     if my_list[i] % 2 == 0:
...         my_list[i] = my_list[i] * 2
...     else:
...         my_list[i] = my_list[i] + 1
>>> print(my_list)
Question 4hardmultiple choice
Full question →

A developer writes: a = 3; b = 4; c = a + b / 2. What is the value of c?

Question 5hardmulti select
Full question →

Which THREE of the following are valid ways to iterate over a list?

Question 6hardmultiple choice
Full question →

Which of the following will raise a TypeError?

Question 7hardmulti select
Full question →

Which TWO of the following expressions will evaluate to True?

Which TWO operators in Python yield an integer result when applied to two integers?

You are maintaining a legacy Python 2.7 script that calculates shipping costs. The script reads weight from user input, then calculates cost as weight * 1.5. Recently, the company upgraded to Python 3.9, and now the script raises a TypeError: can't multiply sequence by non-int of type 'float'. The input line is: weight = input('Enter weight: '). You need to fix the script minimally. Which action should you take?

Question 10hardmultiple choice
Full question →

A junior developer is working on a script that processes user data. The script reads a CSV file into a list of dictionaries. Each dictionary represents a user with keys 'name', 'age', and 'email'. The developer needs to filter out users under 18 and store their names in a list. The current code is:

users = [{'name': 'Alice', 'age': 17, 'email': 'alice@example.com'}, {'name': 'Bob', 'age': 22, 'email': 'bob@example.com'}]

minors = []

for user in users:
    if user['age'] < 18:

minors.append(user['name'])

print(minors)

The code works, but the senior developer says it is not idiomatic and suggests a more concise solution. Which of the following approaches is the best replacement?

A system administrator wrote a Python script to monitor disk usage. The script reads the output of a system command that returns a string like 'Used: 45%' and extracts the percentage. The code uses slicing to get the numeric part and converts to int. However, on some servers, the output format changes to 'Used: 45.2%', causing a ValueError when converting to int. The administrator needs a robust solution that works with both integer and floating-point percentages while still producing an integer result (e.g., 45 for 45.2%). Which option is the best approach?

What is the output of the following code? ```python x = 10 y = 3

print(x // y * y + x % y)

```

Refer to the exhibit. A beginner Python programmer executes the code and gets an error. What is the most likely cause?

Exhibit

>>> x = 10
>>> y = "20"
>>> print(x + y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Question 14hardmultiple choice
Full question →

Consider: x = True; y = False; z = x and not y or x. What is the value of z?

Question 15hardmulti select
Full question →

Which three of the following statements about lists are true? (Choose three.)

Question 16hardmultiple choice
Full question →

What is the output of print(type(3 + 4.5))?

Question 17hardmultiple choice
Full question →

Refer to the exhibit. What is the output of the code?

Exhibit

>>> x = 10
>>> while x > 0:
...     x = x - 3
...     if x == 4:
...         break
... else:
...     print('Loop ended normally')
>>> print(x)
Question 18hardmultiple choice
Full question →

What is the result of the expression: (1 and 0) or (not False and True)?

These PCEP practice questions are part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style PCEP questions with detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics.