Pcep – Certified Entry-Level Python Programmer Free Sample Questions

Create a free account to browse all 20 sample questions. The full practice test includes 192 questions. Use the simulator for timed and flashcard mode.

Try Simulator

PCEP-30-02 Sample Questions

  1. Question 1

    Q1

    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 & explanation

    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.

  2. Question 2

    Q2

    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 & explanation

    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.

  3. Question 3

    Q3

    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 & explanation

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

    Q4

    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 & explanation

    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.

  5. Question 5

    Q5

    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 & explanation

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

  6. Question 6

    Q6

    A data processing script needs to create a new list containing only the lengths of strings from an existing list, but only for strings that have more than 3 characters. Which of the following is the most 'Pythonic' way to achieve this using a single line of code?

    words = ['cat', 'window', 'defenestrate', 'dog']

    Show answer & explanation

    Correct answer: A

    This list comprehension is the most concise and Pythonic solution. It iterates through the words list, applies a filter (if len(w) > 3), and then applies a transformation (len(w)) to each item that passes the filter, all in one readable line.

  7. Question 7

    Q7

    True or False: In Python, the expression 0.1 + 0.2 == 0.3 evaluates to True.

    Show answer & explanation

    Correct answer: B

    This statement is False. Due to the nature of binary floating-point representation, numbers like 0.1 and 0.2 cannot be stored with perfect precision. The result of 0.1 + 0.2 is a value extremely close to, but not exactly, 0.3. This is a fundamental concept in computer science regarding floating-point arithmetic.

  8. Question 8

    Q8

    A developer is writing a validation function that checks if a user's input is within a specific numerical range (inclusive). The function should return True if the number is between 50 and 100, inclusive. Which boolean expression correctly and most concisely implements this logic?

    Show answer & explanation

    Correct answer: B

    Python supports chained comparisons, which allows for a more readable and mathematically intuitive way to check if a value falls within a range. This expression is equivalent to (50 <= number) and (number <= 100) and is the most concise and 'Pythonic' way to write the check.

  9. Question 9

    Q9

    A script needs to iterate through a sequence of numbers from 0 to 9. During the iteration, it should print 'Found it!' and stop processing immediately when it encounters the number 7. For all other numbers before 7, it should just print the number itself. What is the expected output of a correctly written loop for this task?

    Show answer & explanation

    Correct answer: B

    This is the correct output. The loop iterates from 0 up to 6, printing each number. When the loop variable becomes 7, the condition if number == 7 is met, 'Found it!' is printed, and the break statement terminates the loop before it can process any further numbers.

  10. Question 10

    Q10

    A Python dictionary is used to store user preferences. A function needs to retrieve the 'theme' preference. If the 'theme' key does not exist, the function should return 'light' without causing an error and without modifying the original dictionary. Which line of code achieves this safely?

    Show answer & explanation

    Correct answer: C

    The .get() method is the correct and safest way to achieve this. It attempts to retrieve the value for the given key. If the key is not found, it returns the default value provided as the second argument ('light' in this case) instead of raising a KeyError. It does not modify the dictionary.

Register free to unlock 10 more sample questions

Create a free account to continue with the rest of the PCEP-30-02 sample set.

Lifetime One

Own this practice test forever.

$79.99
$75.99
one-time
  • Full access to 192 questions
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • Brainy AI Assistant
  • Lifetime updates

Two

Any 2 exams per month.

$20.00/exam
$39.99
/month
  • 2 active exam slots
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • 1,000 Brainy AI Credits
  • Cancel anytime

Premium Twelve

Any 12 exams over 3 months.

$15.00/exam
$179.99
/3 months
  • 4 active exam slots
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • 15,000 Brainy AI Credits
  • Dedicated support
  • Friend seat included — full access

Trusted by professionals at

NvidiaSupabaseGitHubOpenAITursoClerkClaude AIAmazon