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.

20
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 →

According to PEP 8, which of the following is the recommended way to name a constant representing the maximum number of retries?

Question 2hardmultiple choice
Full question →

Refer to the exhibit. What is the output?

Exhibit

def modify_dict(d):
    d['key'] = 'new_value'
    d = {'another': 'dict'}

my_dict = {'key': 'old_value'}
modify_dict(my_dict)
print(my_dict)
Question 3hardmultiple choice
Full question →

Given the code: x = 10; y = 3.0; z = x / y; print(type(z)). What is the output?

Question 4hardmultiple choice
Full question →

Given the code: my_list = [1, 2, 3, 4, 5]. What is the output of print(my_list[-3:-1])?

Question 5hardmulti select
Full question →

Which THREE of the following expressions evaluate to True?

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 7hardmultiple choice
Full question →

You are working on a network automation script that reads a configuration file containing firewall rules. Each rule is a dictionary with keys 'source_ip', 'dest_ip', 'action'. The script must iterate over the rules and print all rules where action is 'allow'. However, the script is not printing any output even though there are allow rules in the file. The code snippet is:

rules = [{'source_ip':'10.0.0.1','dest_ip':'10.0.0.2','action':'allow'},

{'source_ip':'10.0.0.2','dest_ip':'10.0.0.3','action':'deny'}]
for rule in rules:
    if rule('action') == 'allow':
        print(rule)

What is the most likely cause of the problem?

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?

Question 9hardmultiple choice
Full question →

In a try-except block, a developer has two except clauses: except ValueError: and except: (bare except). If the code in the try block raises a ValueError, which except clause is executed?

Question 10hardmulti select
Full question →

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

Question 11hardmultiple choice
Full question →

What is the output of: print(2 ** 3 ** 2)?

Question 12hardmultiple choice
Full question →

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

Exhibit

>>> def outer(x):
...     def inner(y):
...         return x + y
...     return inner
>>> add5 = outer(5)
>>> add3 = outer(3)
>>> print(add5(10), add3(10))
Question 13hardmultiple 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)
```
Question 14hardmultiple choice
Full question →

Refer to the exhibit. What is the output of Line C?

Exhibit

def func(a, b, c=10, d=20):
    return a + b + c + d

print(func(1, 2, 3, 4))  # Line A
print(func(1, 2, 3))     # Line B
print(func(1, 2))        # Line C
Question 15hardmulti select
Full question →

Which TWO of the following code snippets will result in a SyntaxError? (Choose two.)

Which of the following is the most efficient (Pythonic) way to create a list of squares for numbers 0 through 9?

Question 17hardmultiple choice
Full question →

Which exception is raised when trying to access a dictionary key that does not exist?

Question 18hardmultiple choice
Full question →

A company runs a script that processes user input temperatures. The script expects integers but sometimes users enter floats. The current code is: temp = int(input("Enter temperature: ")). When a user enters "36.5", the script crashes with a ValueError. The developer needs to modify the script to handle both integer and float inputs gracefully, converting the input to an integer (by truncation) for processing. Which of the following is the best course of action?

A company has a Python script that imports a module from a package. The package structure is: mypackage/__init__.py, mypackage/module.py. The script uses 'from mypackage import module'. Which file must exist for this import to work?

Question 20hardmultiple 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)

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.