Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

HomeCertificationsPCEPExam Questions

Python Institute · Free Practice Questions · Last reviewed May 2026

PCEP Exam Questions and Answers

24real exam-style questions organised by domain, each with the correct answer highlighted and a plain-English explanation of why it's right — and why the others are wrong.

30 exam questions
45 min time limit
Pass: 700/1000 / 1000
4 exam domains
OverviewDomain BlueprintStudy GuideAll QuestionsSample by Domain
1. Computer Programming and Python Fundamentals2. Data Types, Variables, Basic I/O and Operators3. Control Flow, Loops, Lists and Logic4. Functions, Tuples, Dictionaries and Exceptions
1

Domain 1: Computer Programming and Python Fundamentals

All Computer Programming and Python Fundamentals questions
Q1
easyFull explanation →

A developer writes a script that prompts the user for their age and stores it in a variable. Which code snippet correctly converts the input to an integer?

A

age = int(input)

B

age = int(input("Enter age: "))

Correctly converts the input string to an integer.

C

age = input("Enter age: ", int)

D

age = input(int("Enter age: "))

Why: Option B is correct because it uses the `int()` function to convert the string returned by `input()` into an integer. The `input()` function always returns a string, so wrapping it with `int()` performs the type conversion needed for numeric operations.
Q2
easyFull explanation →

Which of the following is the correct way to define a function that takes no arguments and returns the value 42?

A

function f(): return 42

B

def f(): return 42

C

def f: return 42

D

def f(): return 42

Correct syntax for a function that returns 42.

Why: Option D is correct because in Python, a function is defined using the `def` keyword, followed by the function name, parentheses (even for no arguments), a colon, and the body with `return 42`. This syntax is required by the Python language specification.
Q3
mediumFull explanation →

A program uses a variable named 'list' that shadows the built-in list type. Later, the code tries to create a new list using list([1,2,3]) but gets a TypeError. What is the most likely cause?

A

The argument [1,2,3] is invalid because it contains integers.

B

The variable 'list' is now an integer or other non-callable type.

Because 'list' was reassigned, it no longer refers to the built-in function.

C

The list constructor expects a tuple, not a list.

D

The code is missing an import for the list type.

Why: When a variable named 'list' is assigned a value (e.g., an integer), it shadows the built-in `list` type in the current scope. Later, calling `list([1,2,3])` attempts to call the variable `list` as a function, but since it now holds a non-callable object (like an integer), Python raises a TypeError. This is a classic name-shadowing issue in Python.
Q4
mediumFull explanation →

A programmer writes: x = 5; y = 2; result = x / y. What is the type of result?

A

int

B

float

True: / operator returns float.

C

str

D

complex

Why: In Python 3, the division operator (/) always returns a floating-point number, even if both operands are integers. Since x and y are both integers (5 and 2), the result of 5 / 2 is 2.5, which is of type float. Therefore, option B is correct.
Q5
hardFull explanation →

Given the code: a = [1, 2, 3]; b = a; b.append(4). What is the value of a?

A

[1, 2, 3, 4]

Both a and b refer to the same list.

B

Error

C

[1, 2, 3]

D

[1, 2, 3, [4]]

Why: Option A is correct because in Python, variables hold references to objects, not copies. When `b = a` is executed, both `a` and `b` point to the same list object in memory. The `append()` method modifies the list in-place, so the change is visible through both references. Thus, `a` becomes `[1, 2, 3, 4]`.
Q6
easyFull explanation →

Which of the following statements about Python indentation is true?

A

Indentation is optional but recommended.

B

You can mix tabs and spaces freely.

C

Indentation must be consistent within a block.

Correct.

D

Indentation only matters for loops and conditionals.

Why: Option C is correct because Python enforces consistent indentation within a block to define the scope of statements. Unlike many languages that use braces, Python relies on the indentation level to group statements, and any inconsistency (e.g., mixing spaces and tabs or varying the number of spaces) will raise an IndentationError.

Want more Computer Programming and Python Fundamentals practice?

Practice this domain
2

Domain 2: Data Types, Variables, Basic I/O and Operators

All Data Types, Variables, Basic I/O and Operators questions
Q1
easyFull explanation →

A developer writes the following code: x = 5; y = 2; print(x // y). What is the output?

A

1

B

2

Floor division of 5 by 2 yields 2.

C

2.0

D

2.5

Why: The floor division operator (//) in Python returns the largest integer less than or equal to the result of the division. Since 5 divided by 2 equals 2.5, the floor is 2, and the result is an integer (int) because both operands are integers. Therefore, the output is 2.
Q2
mediumFull explanation →

A junior developer writes: x = 10; y = 3; print(x % y). What will be printed?

A

3.33

B

1

Remainder when 10 is divided by 3.

C

0

D

3

Why: The modulo operator (%) returns the remainder of the division of the left operand by the right operand. Here, 10 divided by 3 equals 3 with a remainder of 1, so print(x % y) outputs 1.
Q3
hardFull explanation →

A developer needs to convert a string '25' to an integer and then add 10. Which code correctly performs this?

A

print(int('25') + 10)

Correct conversion and addition.

B

print('25' + 10)

C

print(int('25') + '10')

D

print('25' + str(10))

Why: Option A is correct because `int('25')` converts the string '25' to the integer 25, and then `+ 10` performs integer addition, resulting in 35. The `print()` function outputs the result. This follows Python's type conversion rules where explicit conversion is required to combine a string and an integer in arithmetic.
Q4
easyFull explanation →

What is the correct way to read a floating-point number from user input and store it in a variable?

A

x = input(float())

B

x = input() as float

C

x = float(input())

Reads input as string, then converts to float.

D

x = input().float()

Why: Option C is correct because `float(input())` first reads the user input as a string via `input()`, then converts that string to a floating-point number using the `float()` function. This is the standard and only valid way in Python to obtain a float from console input, as `input()` always returns a string.
Q5
mediumFull explanation →

A developer wants to assign the value 3.14 to a variable and later change it to the integer 3. Which of the following is true?

A

This is allowed only if the variable was declared as a float.

B

This causes a TypeError because you cannot change types.

C

This is allowed because Python is dynamically typed.

No type restrictions.

D

This is allowed only if you use the int() function during assignment.

Why: Option C is correct because Python is dynamically typed, meaning variables can be reassigned to values of any type at runtime. The developer can first assign the float 3.14 to a variable and later reassign the integer 3 to the same variable without any type declaration or conversion function required.
Q6
easyFull explanation →

Which of the following is a valid variable name in Python?

A

my-var

B

2nd_place

C

_count

Underscore is allowed at start.

D

class

Why: Option C (_count) is correct because in Python, variable names can start with an underscore, and underscores are allowed anywhere in the name. The name _count follows all Python identifier rules: it starts with a letter or underscore, contains only letters, digits, or underscores, and is not a reserved keyword.

Want more Data Types, Variables, Basic I/O and Operators practice?

Practice this domain
3

Domain 3: Control Flow, Loops, Lists and Logic

All Control Flow, Loops, Lists and Logic questions
Q1
easyFull explanation →

A developer writes a loop to sum numbers from 1 to 10. The code outputs 55, but the expected sum is 55. However, the loop uses a range that includes 0. Which range should be used to achieve the correct sum?

A

range(0,11)

B

range(1,11)

Correctly generates 1..10

C

range(0,101)

D

range(1,10)

Why: Option B (range(1,11)) is correct because range(start, stop) generates numbers from start inclusive to stop exclusive. To sum numbers 1 through 10, the range must start at 1 and end at 11 (so 10 is included). The loop that used range(0,11) included 0, but since adding 0 does not change the sum, the output was still 55 — however, the question asks for the range that achieves the correct sum without including unnecessary values.
Q2
easyFull explanation →

A programmer needs to iterate over a list of strings and print each string in uppercase. Which loop correctly accomplishes this?

A

for i, item in enumerate(mylist): print(item.upper())

Also correct, but the question expects exactly one correct; both A and C are correct. I'll adjust: make only A correct? No, both are valid. I need to change distractors so that only one is correct. Let's replace A with a wrong one.

B

for item in mylist: item = item.upper()

C

for item in mylist: print(item.upper)

D

for i in range(len(mylist)): print(mylist[i].upper())

Correctly accesses each element by index and prints uppercase.

Why: Option A is correct because it uses a for loop with enumerate to iterate over the list, and calls the string method upper() (with parentheses) to convert each item to uppercase before printing. This ensures each string is properly transformed and output.
Q3
mediumFull explanation →

A programmer writes code that uses a while loop to process user input until the user types 'exit'. The code currently prints 'Done' after the loop, but it never exits. What is the most likely cause?

A

The loop condition is 'while True'

B

The print statement is indented incorrectly

C

The input function is called outside the loop

D

The variable controlling the loop is not updated inside the loop

Classic infinite loop cause.

Why: Option D is correct because if the variable controlling the loop (e.g., the user's input) is never updated inside the while loop, the loop condition will never become false, causing an infinite loop. In this scenario, the programmer likely reads input once before the loop but does not call input() again inside the loop to update the variable, so the loop never sees the 'exit' value.
Q4
easyFull explanation →

A list of numbers is defined as nums = [1, 2, 3, 4, 5]. Which expression returns the last element?

A

nums[5]

B

nums[-1]

Correct negative indexing.

C

nums[0]

D

nums[-2]

Why: Option B is correct because Python uses zero-based indexing, so the first element is at index 0 and the last element is at index -1. Negative indices count from the end of the list, so nums[-1] directly accesses the last element (5) without needing to know the list length.
Q5
mediumFull explanation →

A list contains strings and numbers: items = ['apple', 10, 'banana', 20]. A programmer wants to create a new list that contains only the strings. Which approach is correct?

A

[item for item in items if item.isdigit()]

B

[item for item in items if type(item) is 'str']

C

[item for item in items if type(item) == str]

Correct, though isinstance is preferred.

D

[item for item in items if isinstance(item, str)]

Correct and best practice.

Why: Option C is correct because `type(item) == str` directly compares the type of each item to the `str` type object, which returns `True` for strings and `False` for numbers. This is a valid and explicit way to filter the list comprehension to only include string elements.
Q6
hardFull explanation →

A developer writes the following code snippet:

for i in range(3):
    for j in range(2):
        if i == j:

break else:

print(i, 'outer')

What is the output?

A

0 outer\n2 outer

B

2 outer

Only when i=2 does the inner loop complete without break.

C

0 outer\n1 outer\n2 outer

D

No output

Why: The code uses nested loops with a `for-else` construct. The `else` block executes only if the inner loop completes without a `break`. When `i == j`, the `break` exits the inner loop, skipping the `else`. For `i=0`, `j=0` triggers `break`; for `i=1`, `j=1` triggers `break`; for `i=2`, the inner loop runs `j=0,1` without any `i==j` (since 2 != 0 and 2 != 1), so the `else` executes, printing `2 outer`. Thus, only option B is correct.

Want more Control Flow, Loops, Lists and Logic practice?

Practice this domain
4

Domain 4: Functions, Tuples, Dictionaries and Exceptions

All Functions, Tuples, Dictionaries and Exceptions questions
Q1
easyFull explanation →

A developer writes a function to calculate the average of a list of numbers, but the function sometimes returns a wrong result when the list contains non-numeric values. What is the best way to handle this?

A

Return None if any non-numeric value is encountered.

B

Use try-except to ignore non-numeric values and proceed with the remaining numbers.

C

Convert all values to string and concatenate them.

D

Check that all items are numeric before calculation, and raise TypeError otherwise.

Raising an exception is the standard way to handle invalid input.

Why: Option D is correct because it explicitly validates that all items are numeric before performing the calculation, raising a TypeError if any non-numeric value is found. This follows Python's principle of explicit error handling and ensures the function's contract is clear: it only works with numeric data. Returning None (A) or silently ignoring values (B) can lead to subtle bugs, while converting to strings (C) would produce a concatenated string, not an average.
Q2
mediumFull explanation →

A Python script uses a dictionary to store user session data. The developer writes `user = {'id': 101, 'name': 'Alice'}` and later tries to access `user['email']`. What is the outcome?

A

It returns an empty string.

B

It raises a KeyError.

Accessing a non-existent key directly raises KeyError.

C

It returns None.

D

It checks the 'in' operator automatically and returns False.

Why: In Python, accessing a dictionary key that does not exist raises a KeyError. The dictionary `user` contains only the keys 'id' and 'name', so `user['email']` triggers a KeyError because the key 'email' is not present. This is a fundamental behavior of Python dictionaries, which do not return default values for missing keys unless a method like `.get()` is used.
Q3
hardFull explanation →

A server logs are stored as a list of tuples: `logs = [('2024-01-10', 'INFO', 'Started'), ('2024-01-10', 'ERROR', 'Disk full')]`. A developer wants to count how many ERROR logs exist. Which code snippet correctly counts them?

A

count = logs.count(('ERROR',))

B

count = sum(log[1] == 'ERROR' for log in logs)

Sum of booleans gives the count.

C

count = [log for log in logs if log[1] == 'ERROR']

D

count = len(logs)

Why: Option B uses a generator expression with `sum()` to count how many tuples in the `logs` list have the second element equal to `'ERROR'`. The expression `log[1] == 'ERROR'` evaluates to `True` (which is treated as 1) or `False` (0) for each tuple, and `sum()` adds them up, giving the correct count of ERROR logs.
Q4
easyFull explanation →

A function `def process(data):` modifies the dictionary passed as argument by adding a new key. The developer wants to avoid modifying the original dictionary. What should the function do?

A

Create a copy of the dictionary at the start: `data = data.copy()`

copy() creates a shallow copy, avoiding modification of original.

B

Add the key, then delete it at the end.

C

Modify directly; changes to mutable objects are local only.

D

Convert the dictionary to a tuple before processing.

Why: Option A is correct because dictionaries are mutable objects in Python, so passing a dictionary to a function passes a reference to the same object. Calling `data.copy()` creates a shallow copy of the dictionary, allowing the function to modify the copy without affecting the original dictionary. This is the standard Pythonic way to avoid side effects on mutable arguments.
Q5
mediumFull explanation →

A developer writes a function that returns multiple values as a tuple. Which of the following is a valid way to unpack the result into separate variables?

A

result = func(); a, b = result[0], result[1]

B

a, b, c = func()

C

a = func()[0]; b = func()[1]

D

a, b = func()

This is direct tuple unpacking.

Why: Option D is correct because when a function returns multiple values as a tuple, Python allows tuple unpacking directly in an assignment statement. The syntax `a, b = func()` automatically unpacks the two-element tuple into the variables `a` and `b`, which is the standard and most Pythonic way to handle such a return.
Q6
hardFull explanation →

A Python script processes a list of tuples representing coordinates: `points = [(1,2), (3,4), (5,6)]`. The developer wants to create a dictionary mapping each coordinate to its distance from origin. Which code correctly creates the dictionary?

A

distances = {}; for point in points: distances[point] = (point[0]**2 + point[1]**2)

B

distances = {}; for point in points: distances[point] = (point[0]**2 + point[1]**2)**0.5

C

distances = {point: (point[0]**2 + point[1]**2)**0.5 for point in points}

Dictionary comprehension with correct calculation.

D

distances = {point: point[0]**2 + point[1]**2 for point in points}

E

distances = [(point, (point[0]**2 + point[1]**2)**0.5) for point in points]

Why: Option C is correct because it uses a dictionary comprehension to map each tuple (coordinate) to its Euclidean distance from the origin, calculated as `(point[0]**2 + point[1]**2)**0.5`. This correctly produces a dictionary with tuples as keys and float distances as values, matching the requirement exactly.

Want more Functions, Tuples, Dictionaries and Exceptions practice?

Practice this domain

Frequently asked questions

How many questions are on the PCEP exam?

The PCEP exam has 30 questions and must be completed in 45 minutes. The passing score is 700/1000.

What types of questions appear on the PCEP exam?

Scenario-based questions covering exam objectives with detailed answer explanations.

How are PCEP questions organised by domain?

The exam covers 4 domains: Computer Programming and Python Fundamentals, Data Types, Variables, Basic I/O and Operators, Control Flow, Loops, Lists and Logic, Functions, Tuples, Dictionaries and Exceptions. Questions are weighted by domain — higher-weight domains appear more on your actual exam.

Are these the actual PCEP exam questions?

No. These are original exam-style practice questions written against the official Python Institute PCEP exam objectives. They are not copied from the real exam. Courseiva focuses on genuine understanding, not memorisation of braindumps.

Ready to practice all 30 PCEP questions?

Courseiva tracks your accuracy per domain and routes you toward weak areas automatically. Free, no account required.

Browse all PCEP questionsTake a timed practice test