Courseiva

PCEP · topic practice

Computer Programming and Python Fundamentals practice questions

This domain covers the foundations every PCEP candidate needs: how Python source is structured, how names and literals are written, and how basic expressions evaluate. Questions are short code-reading and output-prediction items, plus PEP 8 style recognition and choosing the right built-in data structure for a described configuration or record.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Editorial oversight:Johnson Ajibi· MSc IT Security, IEEE Senior Member
18 questionsDomain: Computer Programming and Python Fundamentals

What the exam tests

What to know about Computer Programming and Python Fundamentals

You must read short snippets and state exactly what prints, and recognize idiomatic Python naming and structure choices. The single most important thing is to trace expression evaluation and slicing precisely, remembering that slice stops are exclusive and that ** has higher precedence than unary minus.

PEP 8 naming conventions for variables, constants, functions, classes, and modules

Python literal and operator behavior, including exponentiation, precedence, and integer versus float results

Indexing and slicing of sequences, including negative indices and slice end exclusivity

Selecting appropriate built-in types such as list, tuple, dict, and set for a given data shape

Why learners struggle

Why Computer Programming and Python Fundamentals questions are commonly missed

RAM questions are commonly missed because learners confuse physical form factors (DIMM vs SO-DIMM) and fail to distinguish between memory speed (MHz) and latency (CL).

  • ·DIMM vs SO-DIMM — desktop vs laptop form factor confusion
  • ·DDR3 vs DDR4 vs DDR5 — notch position and voltage differences
  • ·MHz vs CL — speed vs latency trade-offs in performance
  • ·Single-channel vs dual-channel — bandwidth impact misconception
  • ·ECC vs non-ECC — error correction support in servers vs desktops
  • ·32-bit vs 64-bit — maximum addressable RAM limit

Watch out for

Common Computer Programming and Python Fundamentals exam traps

  • ▸Assuming a slice like [-3:-1] includes the last element; the stop index is always excluded, so the final item is dropped.
  • ▸Forgetting that ** binds tighter than unary minus and multiplication, so -2 ** 2 evaluates to -4, not 4.
  • ▸Using camelCase or single-letter names for constants; PEP 8 expects UPPER_CASE_WITH_UNDERSCORES for module-level constants.

Practice set

Computer Programming and Python Fundamentals questions

18 questions · select your answer, then reveal the 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?

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

Question 3mediummultiple choice
Study the full Python automation breakdown →

A student writes the code: x = 10; if x > 5: print("big"); else: print("small"). What is the output?

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

Question 5mediummultiple choice
Study the full Python automation breakdown →

A system administrator is writing a Python script to monitor disk usage. The script uses the psutil library (not part of PCEP scope, but the scenario is generic). The administrator writes:

import psutil

disk = psutil.disk_usage('/')

print(disk.free)

But the script fails with an ImportError because psutil is not installed. The administrator decides to handle this gracefully: if the module is missing, the script should print a custom error message and exit without crashing. Which code snippet achieves this?

Question 6mediummultiple choice
Study the full Python automation breakdown →

A developer writes a Python script that calculates the average of a list of numbers. The script sometimes produces a ZeroDivisionError. Which of the following is the MOST appropriate way to handle this error to keep the script running?

A Python script contains the following line: x = 5. Later in the script, the programmer wants to check if x is an integer. Which of the following is the BEST way to perform this check?

Which TWO of the following are valid Python variable names? (Choose two.)

Question 9mediummultiple choice
Study the full Python automation breakdown →

What is the output of the code in the exhibit?

Exhibit

Refer to the exhibit.

```
x = '10'
y = 5
result = x + y
print(result)
```

What is the output of the code in the exhibit?

Exhibit

Refer to the exhibit.

```
my_list = [1, 2, 3, 4, 5]
my_list[1:3] = [10, 20]
print(my_list)
```

A Python script uses the following code to open a file: f = open('data.txt', 'w'). The programmer then writes multiple lines to the file. After writing, which of the following is the BEST practice to ensure data integrity?

Question 12mediummultiple choice
Study the full Python automation breakdown →

A junior developer is tasked with writing a Python script that reads a list of integers from a file, removes any duplicate numbers, and then writes the unique numbers back to the same file in ascending order. The file 'numbers.txt' currently contains one integer per line. The developer writes the following code:

with open('numbers.txt', 'r') as f:

numbers = [int(line.strip()) for line in f] unique = list(set(numbers)) unique.sort()

with open('numbers.txt', 'w') as f:
    for num in unique:

f.write(str(num) + '\n')

The script runs without errors, but the output file contains the numbers in descending order instead of ascending. The developer checks the sort() method and confirms it sorts in ascending order. What is the MOST likely cause of the issue?

Match each Python list method to its effect.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Adds an item to the end of the list

Inserts an item at a given position

Removes the first occurrence of a value

Removes and returns an item at a given index

Sorts the list in ascending order in place

Question 14mediummultiple choice
Study the full Python automation breakdown →

A data scientist has a list: scores = [88, 92, 79, 93, 85]. They want to add 5 bonus points to each score and store the new scores. Which code accomplishes this?

Question 15mediummultiple choice
Study the full Python automation breakdown →

A developer wants to extract the file extension from a filename: 'report.pdf'. Which string method will return 'pdf'?

Which THREE of the following will correctly iterate over all keys and values of a dictionary d = {'a':1, 'b':2}?

Consider the following code:

x = input('Enter a number: ')

print(x + x)

A user enters 5 at the prompt. What is printed?

Exhibit

Refer to the exhibit.
# Python script: convert.py
x = input('Enter number: ')
y = x * 2
print(y)
--- End of exhibit ---

The above JSON is loaded into a Python dictionary named data using json.load(). A developer writes:

print(data['languages'][1][:3])

What is printed?

Exhibit

Refer to the exhibit.
{
  "name": "Alice",
  "age": 30,
  "city": "New York",
  "languages": ["Python", "Java"]
}
--- End of exhibit ---

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Computer Programming and Python Fundamentals sessions

Start a Computer Programming and Python Fundamentals only practice session

Every question in these sessions is drawn from the Computer Programming and Python Fundamentals domain — nothing else.

Related practice questions

Related PCEP topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the PCEP exam test about Computer Programming and Python Fundamentals?
You must read short snippets and state exactly what prints, and recognize idiomatic Python naming and structure choices. The single most important thing is to trace expression evaluation and slicing precisely, remembering that slice stops are exclusive and that ** has higher precedence than unary minus.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Computer Programming and Python Fundamentals questions in a focused session?
Yes — the session launcher on this page draws every question from the Computer Programming and Python Fundamentals domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other PCEP topics?
Use the topic links above to move to related areas, or go back to the PCEP question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the PCEP exam covers. They are not copied from any real exam or dump site.