PCEP-30-02: Python Fundamentals

Try 10 focused PCEP-30-02 questions on Python Fundamentals, with explanations, then continue with IT Mastery.

On this page

Open the matching IT Mastery practice page for timed mocks, topic drills, progress tracking, explanations, and full practice.

Try PCEP-30-02 on Web View full PCEP-30-02 practice page

Topic snapshot

FieldDetail
Exam routePCEP-30-02
Topic areaBlock 1: Computer Programming and Python Fundamentals
Blueprint weight18%
Page purposeFocused sample questions before returning to mixed practice

How to use this topic drill

Use this page to isolate Block 1: Computer Programming and Python Fundamentals for PCEP-30-02. Work through the 10 questions first, then review the explanations and return to mixed practice in IT Mastery.

PassWhat to doWhat to record
First attemptAnswer without checking the explanation first.The fact, rule, calculation, or judgment point that controlled your answer.
ReviewRead the explanation even when you were correct.Why the best answer is stronger than the closest distractor.
RepairRepeat only missed or uncertain items after a short break.The pattern behind misses, not the answer letter.
TransferReturn to mixed practice once the topic feels stable.Whether the same skill holds up when the topic is no longer obvious.

Blueprint context: 18% of the practice outline. A focused topic score can overstate readiness if you recognize the pattern too quickly, so use it as repair work before timed mixed sets.

Sample questions

These questions are original IT Mastery practice items aligned to this topic area. They are designed for self-assessment and are not official exam questions.

Question 1

Topic: Block 1: Computer Programming and Python Fundamentals

A student is cleaning up a beginner Python program and wants variable names that do not conflict with Python keywords. Which TWO proposed names can be used directly as variable names?

Options:

  • A. count

  • B. class

  • C. while

  • D. user_name

  • E. return

  • F. for

Correct answers: A and D

Explanation: Python keywords are reserved words with a special meaning in the language, so they cannot be used as variable names. count and user_name are regular identifiers, while the other choices are reserved words used by Python syntax.

In Python, a keyword is a reserved word that already has a built-in role in the language. Keywords are part of Python syntax for things like loops, function behavior, and class definitions, so you cannot reuse them as variable names. Names such as count and user_name are ordinary identifiers because they are not on Python’s keyword list.

When checking a possible variable name for this kind of question, the key test is simple: if the word is a Python keyword, do not use it as a variable name. Trying to assign to a keyword causes a syntax error. A common beginner mistake is assuming that any common English word is fine, but words like for, while, and return are reserved.

  • while is a loop keyword, so Python does not allow it as a variable name.
  • return is reserved for sending a value back from a function, so it cannot be used as an identifier name.
  • class is reserved for defining classes, so it is not available as a variable name.
  • for is a loop keyword, so using it as a variable name causes a syntax error.

Question 2

Topic: Block 1: Computer Programming and Python Fundamentals

What is printed by this Python 3 code?

a = 10
b = 0b10
c = 0o10
d = 0x10

print(a + b + c + d)

Options:

  • A. It raises a SyntaxError

  • B. 40

  • C. 46

  • D. 36

Best answer: D

Explanation: Python allows integer literals in different bases. Here, 0b10 is 2, 0o10 is 8, and 0x10 is 16, so adding them to decimal 10 prints 36.

The key concept is that Python integer literals can be written in several numeral systems. A plain number like 10 is decimal, while 0b starts a binary literal, 0o starts an octal literal, and 0x starts a hexadecimal literal.

  • 10 = 10
  • 0b10 = 2
  • 0o10 = 8
  • 0x10 = 16

Adding them gives 10 + 2 + 8 + 16, which is 36. The important point is that the prefixes change the base of the literal; they are not just extra characters in front of decimal 10.

  • Treating all as decimal leads to 40, but the 0b, 0o, and 0x prefixes change the values.
  • Knowing only hexadecimal can lead to 46, but 0b10 and 0o10 are 2 and 8, not 10.
  • Expecting a syntax error is incorrect because all three prefixed forms are valid Python 3 integer literals.

Question 3

Topic: Block 1: Computer Programming and Python Fundamentals

A student wants this program to run without changing its if/else logic. Which replacement should be used everywhere 2nd_choice appears?

2nd_choice = input("Enter Y or N: ")

if 2nd_choice == "Y":
    print("Continue")
else:
    print("Stop")

Options:

  • A. 2ndChoice

  • B. for

  • C. second_choice

  • D. second-choice

Best answer: C

Explanation: The only valid replacement is second_choice. Python variable names may contain letters, digits, and underscores, but they cannot start with a digit or use a reserved keyword, so this name fixes the code while leaving the if/else behavior unchanged.

Python variable names are identifiers. They may use letters, digits, and underscores, but they cannot begin with a digit and cannot be reserved words such as for. In this program, the if/else already represents the intended control flow; the problem is only that 2nd_choice is not a legal identifier. Replacing it with second_choice everywhere keeps the same comparison and makes the code valid.

  • Starts with a letter
  • Uses only letters and _
  • Is not a reserved keyword

A name like 2ndChoice may look descriptive, but it still fails because the first character is a digit.

  • 2ndChoice is still invalid because identifiers cannot start with a digit.
  • for is a reserved keyword, so it cannot be used as a variable name.
  • second-choice is invalid because the hyphen is treated as the subtraction operator.

Question 4

Topic: Block 1: Computer Programming and Python Fundamentals

A student is testing a short Python script and wants to know which lines Python ignores because they are comments. In the program below, which TWO lines are ignored for that reason?

1 total = 3
2 # total = total + 2
3 print("Items:", total)
4 print("# done")
5 total = total + 1  # add bonus item
6 # print(total)

Options:

  • A. Line 5: total = total + 1 # add bonus item

  • B. Line 3: print("Items:", total)

  • C. Line 6: # print(total)

  • D. Line 2: # total = total + 2

  • E. Line 4: print("# done")

Correct answers: C and D

Explanation: In Python, a full line that begins with # is a comment and is ignored by the interpreter. Here, only the two lines made entirely of comment text are skipped; the line with # inside quotes and the line with code before # are still executable instructions.

Python uses # to start a comment. When a line contains only a comment, that entire line is ignored and no instruction runs. That is what happens on the two full-line comment entries in the snippet.

A # does not always mean the whole line is ignored:

  • If # appears inside quotes, it is just part of a string.
  • If code appears before #, Python executes the code and ignores only the text after #.
  • Regular assignment and print() lines are normal executable instructions.

The closest trap is the line with an inline comment, because only the comment part is skipped, not the assignment itself.

  • print("Items:", total) is a normal executable print() instruction.
  • print("# done") is executable because the # is inside a string literal.
  • total = total + 1 # add bonus item still runs the assignment; only the text after # is ignored.

Question 5

Topic: Block 1: Computer Programming and Python Fundamentals

A student is filling the missing value in this loop. They want the code to print three lines, and the replacement itself must be a single integer literal.

for i in range(?):
    print(i)

Which replacement for ? meets both requirements?

Options:

  • A. 3.0

  • B. 3

  • C. "3"

  • D. 1 + 2

Best answer: B

Explanation: An integer literal is a whole number written directly in code, such as 3. Here, range(3) makes the for loop run three times, printing 0, 1, and 2. The other choices are either not integer literals or are not a single literal.

The core concept is distinguishing an integer literal from other literal types and from expressions. In Python, an integer literal is written directly as a whole number with no quotes and no decimal point, such as 0, 7, or 3. In this loop, range(3) creates three values: 0, 1, and 2, so the loop body executes three times.

  • 3 is a single integer literal.
  • 3.0 is a float literal.
  • "3" is a string literal.
  • 1 + 2 evaluates to an integer, but it is an expression, not one literal.

A value can result in an integer without being written as an integer literal.

  • 3.0 fails because it is a float literal, not an integer literal.
  • "3" fails because quoted text is a string literal.
  • 1 + 2 gives the right numeric result, but it is an expression rather than one literal.

Question 6

Topic: Block 1: Computer Programming and Python Fundamentals

A student is tracing this code and wants to separate variable names from the values currently associated with them.

x = 5
y = x
x = 8

After the code runs, which TWO statements are correct?

Options:

  • A. y is a variable name, and its current value is 5.

  • B. After x = 8, x is no longer a variable name.

  • C. 5 is a variable name because it was assigned to y.

  • D. On the last line, 8 is the variable name and x is the value.

  • E. x is a variable name, and its current value is 8.

  • F. Reassigning x to 8 also changes y to 8.

Correct answers: A and E

Explanation: Variable names are identifiers like x and y; values are the data currently stored under those names. After y = x, both names refer to 5, but x = 8 changes only x, so x ends with 8 and y remains 5.

In Python, a variable name is the identifier used to refer to data, while a value is the actual data currently associated with that name. In this snippet, x first gets the value 5. Then y = x assigns y the current value of x, so y also becomes 5. The final line, x = 8, reassigns only the name x to a new value.

That means the final state is:

  • x - 8
  • y - 5

A common mistake is to confuse the literal on the right side of = with a variable name, or to assume changing one name always changes another.

  • Literals vs names treats 5 or 8 as identifiers, but they are numeric literals, not variable names.
  • Shared change assumes y must change when x changes, even though y already got its own assigned value.
  • Reversed assignment swaps the roles of the left and right sides of x = 8.
  • Name disappears misunderstands reassignment; x stays a variable name after its value changes.

Question 7

Topic: Block 1: Computer Programming and Python Fundamentals

A student wants a loop to run 1,000 times and writes:

count = 1e3
for i in range(count):
    print(i)

The program stops with:

TypeError: 'float' object cannot be interpreted as an integer

What is the best explanation for this error?

Options:

  • A. 1e3 is 1000.0, and range() needs an integer.

  • B. 1e3 is text until float() converts it.

  • C. range() cannot use a variable as its stop value.

  • D. Scientific notation must use uppercase E, not lowercase e.

Best answer: A

Explanation: Scientific notation like 1e3 is valid Python, but it creates a floating-point value. Here, count becomes 1000.0, and range() requires an integer, so the loop raises a TypeError.

In Python, a numeric literal written with e or E uses scientific notation and produces a float. So 1e3 means \(1 \times 10^3\), which is 1000.0, not the integer 1000. That matters because range() is used for counting with whole numbers and does not accept a float argument.

A common fix is to use an integer value for the loop bound, such as 1000, or convert the float explicitly with int() if appropriate. The important point is not the size of the number, but its type.

The closest misconception is thinking that lowercase e is invalid; both e and E are valid in Python scientific notation.

  • The option claiming lowercase e is invalid fails because Python accepts both e and E in scientific notation.
  • The option claiming range() cannot use a variable fails because variables work fine when they contain integers.
  • The option claiming 1e3 is text fails because unquoted numeric literals are numbers, not strings.

Question 8

Topic: Block 1: Computer Programming and Python Fundamentals

Python 3 is installed and available as python. A beginner saves this program as hello.py:

print("Hello")

In a terminal, he types hello.py and the shell says the command is not found. What is the best next fix?

Options:

  • A. Rename the file to hello.exe and run it again.

  • B. Change the line to print Hello.

  • C. Compile hello.py into a standalone executable first.

  • D. Run python hello.py in the terminal.

Best answer: D

Explanation: Python source files are normally run by the Python interpreter. Since Python is already installed, the correct next step is to start the script with python hello.py, not to build a standalone executable.

The core concept is how Python code is executed. A Python program is usually run by the Python interpreter, which reads the .py source file and executes it. In this case, typing hello.py makes the shell try to find a directly runnable command with that exact name, so the shell reports that it cannot find it.

The correct fix is to call the interpreter explicitly with the script name, such as python hello.py. Python does not need to be turned into a standalone .exe before it can run. Renaming the file also does not change its format, and changing valid print() syntax would only create a new problem. The key takeaway is that Python source code normally runs through the interpreter.

  • The option claiming a standalone executable is required confuses optional packaging with normal Python script execution.
  • The option suggesting a .exe rename changes only the filename, not the program format.
  • The option removing the parentheses from print() creates invalid Python 3 syntax and does not fix the shell problem.

Question 9

Topic: Block 1: Computer Programming and Python Fundamentals

A small checkout program should subtract a discount from a price and then use if/else to print low when the discounted price is below 10. The user enters 19.99 for price and 5 for discount.

Which revision makes the if/else block work correctly?

price = input("Price: ")
discount = input("Discount: ")
final = price - discount

if final < 10:
    print("low")
else:
    print("high")

Options:

  • A. Convert both input() results with float() when reading them.

  • B. Keep the input lines, but write final = float(price - discount).

  • C. Keep final as written, but change the condition to if float(final) < 10:.

  • D. Convert both input() results with int() when reading them.

Best answer: A

Explanation: input() always returns strings. Because the program uses subtraction before the if/else decision, the values must be converted to numbers first, and float() is the right choice because 19.99 is not an integer.

The key concept is that console input arrives as text, not as a numeric type. In this program, price - discount is numeric arithmetic, so both values must be converted before that line runs. With float(input(...)), the program calculates 19.99 - 5.0, giving 14.99, and the else branch prints high.

Using int() does not fit the given input because int("19.99") raises ValueError. Converting after the subtraction or only inside the condition is too late, because the program already fails when it tries to evaluate price - discount while both values are still strings.

Convert input() values at the moment you read them when you plan to use them in arithmetic.

  • Using int() fails because 19.99 cannot be converted directly with int().
  • Converting after subtraction fails because Python tries to subtract two strings before float() can run.
  • Converting only in the condition is too late because final was not created successfully.

Question 10

Topic: Block 1: Computer Programming and Python Fundamentals

What is printed by this Python 3 code?

value = 5
print(value--2)

Options:

  • A. 3

  • B. It raises a SyntaxError

  • C. -7

  • D. 7

Best answer: D

Explanation: The code prints 7. Python does not treat -- as a decrement operator here; it treats the first - as binary subtraction and the second - as unary negation, so the expression becomes 5 - (-2).

In Python, the - symbol can be used in two different ways. As a binary operator, it subtracts one value from another. As a unary operator, it changes a number to its negative form. In value--2, Python parses the expression as value - -2, not as a special -- operator.

  • value is 5
  • the first - means subtraction
  • the second - means “negative 2”
  • so the expression is 5 - (-2)

Subtracting a negative number is the same as adding that number, so the result is 7. The closest wrong idea is assuming Python uses -- as a decrement operator, but it does not.

  • Output 3 comes from treating the second minus as ordinary subtraction instead of unary negation.
  • Output -7 would require a different grouping than Python applies to this expression.
  • SyntaxError is tempting if you expect -- to be invalid, but this expression is legal in Python.

Continue with full practice

Use the PCEP-30-02 Practice Test page for the full IT Mastery route, mixed-topic practice, timed mock exams, explanations, and web/mobile app access.

Try PCEP-30-02 on Web View PCEP-30-02 Practice Test

Free review resource

Read the PCEP-30-02 Cheat Sheet on Tech Exam Lexicon, then return to IT Mastery for timed practice.

Revised on Thursday, May 14, 2026