PCEP-30-02 Pcep – Certified Entry-Level Python Programmer Practice Questions
Prepare for PCEP-30-02 with more than an answer.
- Exam fee
- $59 USD
- Level
- Entry-Level
- Valid for
- Lifetime
Domains covered on the exam 4
- Computer Programming and Python Fundamentals18%
- Control Flow – Conditional Blocks and Loops29%
- Data Collections – Tuples, Dictionaries, Lists, and Strings25%
- Functions and Exceptions28%
- 1
A financial services company needs a Python function to process a list of transactions. The function must handle different types of errors that can occur when accessing transaction details from a dictionary. The function should ignore
KeyErrorif a transaction ID is not found, log a specific message forTypeErrorif a value has the wrong type, and stop execution for any otherException.Which
try-exceptblock structure correctly implements this error handling logic?Show answer details
Correct answer: C
This is the correct structure. Python checks
exceptblocks in order. By placing the most specific exceptions (KeyError,TypeError) first, they are handled appropriately. The generalexcept Exception:at the end acts as a catch-all for any other unexpected exceptions, fulfilling all requirements. - 2
What is the result of the following bitwise operation in Python?
print(10 & 12)Show answer details
Correct answer: B
The bitwise AND (
&) operator compares each bit of the two numbers.
The binary representation of 10 is1010.
The binary representation of 12 is1100.
Comparing them bit by bit:1010& 1100----1000
The resulting binary1000is equal to 8 in decimal. - 3
A developer needs to remove all trailing whitespace from a string variable
user_input. Which string method should be used?Show answer details
Correct answer: D
The
rstrip()method specifically removes whitespace from the end (right side or trailing) of the string, which matches the requirement exactly. - 4
What is the value of the
my_listafter this code has been executed?my_list = [1, 2, 3, 4, 5] del my_list[1:3]Show answer details
Correct answer: C
The
delstatement with a slice[1:3]removes elements starting at index 1 up to (but not including) index 3. In the list[1, 2, 3, 4, 5], this corresponds to the elements at index 1 (value 2) and index 2 (value 3). The remaining elements are[1, 4, 5]. - 5
A program requires a loop that prints numbers from 10 down to 1, inclusive. Which
range()function call will generate the required sequence for the loop?Show answer details
Correct answer: B
To count down, the
stepargument must be negative. Thestartvalue is 10. To include 1, thestopvalue must be 0, as the sequence stops just before this value. Therefore,range(10, 0, -1)correctly generates10, 9, 8, 7, 6, 5, 4, 3, 2, 1. - 6
A developer is writing a script to process sensor data. The script receives a hexadecimal string representing a temperature reading, such as '0x1A'. The goal is to convert this string into its decimal integer equivalent. Which line of code correctly performs this conversion?
Show answer details
Correct answer: A
The
int()function can take a second argument for the base. When the base is set to 0, Python automatically infers the base from the string's prefix. '0x' indicates hexadecimal (base 16), '0o' indicates octal (base 8), and '0b' indicates binary (base 2). This is the most robust way to handle prefixed numeral strings. - 7
A Python script is designed to run indefinitely, polling a network service every 10 seconds. An engineer wants to ensure that if the user presses
Ctrl+C, the script prints a friendly 'Shutting down...' message instead of crashing with a traceback. Which exception should be caught to handle this specific interruption?Show answer details
Correct answer: B
KeyboardInterruptis the specific exception raised when the user hits the interrupt key, which is typicallyCtrl+C. Catching this exception allows for graceful shutdown logic. - 8
What is the final value of
resultafter the following code is executed?items = [10, 20, 30, 40, 50] result = 0 for i in range(len(items)): if items[i] > 30: break if items[i] % 20 == 0: continue result += items[i]Show answer details
Correct answer: D
The loop proceeds as follows:
items[0]is 10. It's not > 30. It's not divisible by 20.resultbecomes 10.items[1]is 20. It's not > 30. It IS divisible by 20, socontinueis executed, skipping the rest of the loop body.resultremains 10.items[2]is 30. It's not > 30. It's not divisible by 20.resultbecomes 10 + 30 = 40.items[3]is 40. It IS > 30, sobreakis executed, terminating the loop.
The final value ofresultis 40.
- 9
A programmer creates a tuple containing a list. They then attempt to modify an element within that list. What is the outcome of this operation?
data_tuple = (1, 2, [3, 4]) data_tuple[2][0] = 99 print(data_tuple)Show answer details
Correct answer: C
This is correct. Tuples are immutable, meaning you cannot change the references to the objects they contain. However, if one of those objects is mutable (like a list), you can modify the internal state of that object. The tuple still holds a reference to the same list, but the list's content has changed.
- 10
A developer needs to create a function
calculate_pricethat accepts a base price and an optional discount percentage. If the discount is not provided, it should default to 10%. Which function signature correctly implements this requirement?Show answer details
Correct answer: B
This is the correct syntax. The required parameter
base_priceis listed first, followed by the optional parameterdiscountwith its default value. This allows the function to be called ascalculate_price(100)orcalculate_price(100, 0.2).
