Skip to content

PCEP-30-02 Pcep – Certified Entry-Level Python Programmer Practice Questions

Prepare for PCEP-30-02 with more than an answer.

192 questions in the full set20 sample questionsUpdated Aug 11, 2025
Exam fee
$59 USD
Level
Entry-Level
Valid for
Lifetime
Domains covered on the exam 4
  1. Computer Programming and Python Fundamentals18%
  2. Control Flow – Conditional Blocks and Loops29%
  3. Data Collections – Tuples, Dictionaries, Lists, and Strings25%
  4. Functions and Exceptions28%
  1. 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 KeyError if a transaction ID is not found, log a specific message for TypeError if a value has the wrong type, and stop execution for any other Exception.

    Which try-except block structure correctly implements this error handling logic?

    Show answer details

    Correct answer: C

    This is the correct structure. Python checks except blocks in order. By placing the most specific exceptions (KeyError, TypeError) first, they are handled appropriately. The general except Exception: at the end acts as a catch-all for any other unexpected exceptions, fulfilling all requirements.

  2. 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 is 1010.
    The binary representation of 12 is 1100.
    Comparing them bit by bit:
    1010
    & 1100
    ----
    1000
    The resulting binary 1000 is equal to 8 in decimal.

  3. 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. 4

    What is the value of the my_list after this code has been executed?

    my_list = [1, 2, 3, 4, 5]
    del my_list[1:3]
    
    Show answer details

    Correct answer: C

    The del statement 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. 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 step argument must be negative. The start value is 10. To include 1, the stop value must be 0, as the sequence stops just before this value. Therefore, range(10, 0, -1) correctly generates 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.

  6. 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. 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

    KeyboardInterrupt is the specific exception raised when the user hits the interrupt key, which is typically Ctrl+C. Catching this exception allows for graceful shutdown logic.

  8. 8

    What is the final value of result after 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. result becomes 10.
    • items[1] is 20. It's not > 30. It IS divisible by 20, so continue is executed, skipping the rest of the loop body. result remains 10.
    • items[2] is 30. It's not > 30. It's not divisible by 20. result becomes 10 + 30 = 40.
    • items[3] is 40. It IS > 30, so break is executed, terminating the loop.
      The final value of result is 40.
  9. 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. 10

    A developer needs to create a function calculate_price that 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_price is listed first, followed by the optional parameter discount with its default value. This allows the function to be called as calculate_price(100) or calculate_price(100, 0.2).

Create an account to continue.