PCEP-30-03

Free PCEP-30-03 practice questions

10 questions from our PCEP-30-03 practice tests, each with the correct answer and a written explanation. Read them with the answers shown, or switch to quiz mode and answer first.

Back to the PCEP-30-03 practice exams

Question 1 of 10, Computer Programming and Python Fundamentals

A student asks what happens when the CPython interpreter runs the command python3 report.py. Which description is accurate?

  1. AEach source line is executed directly as text, with no intermediate form ever produced.
  2. BThe script is linked with the standard library into one binary before any line can run.
  3. CThe source is compiled into bytecode, which the Python virtual machine then executes. Correct answer
  4. DThe whole program is translated into native machine code and saved as an .exe file first.

Answer and explanation: CPython first compiles source code into bytecode and the Python virtual machine interprets that bytecode, which is why Python is described as an interpreted language. It does not produce a native executable like a C compiler, and it does not run raw text line by line without an intermediate form. Nothing is statically linked into a standalone binary before execution.

Question 2 of 10, Computer Programming and Python Fundamentals

A sorting tool compares strings with relational operators. What is printed? print("apple" < "banana", "Zoo" < "apple", "10" < "9")

  1. ATrue False True
  2. BTrue True True Correct answer
  3. CFalse True False
  4. DTrue False False

Answer and explanation: Strings are compared character by character using their Unicode code points. a comes before b; uppercase Z (90) has a lower code point than lowercase a (97); and the character 1 comes before 9, so the string 10 is less than 9 even though the number is larger. The distractors assume alphabetical order ignoring case or numeric comparison of digit strings.

Question 3 of 10, Control Flow: Conditional Blocks and Loops

A size classifier contains the branches below. A tester notices that the message huge is never printed, even for x = 80. What is the reason? if x > 10: print("big") elif x > 50: print("huge")

  1. AAn elif branch is evaluated only when the preceding if condition raised an error.
  2. BEvery value above 50 is also above 10, so the first branch always matches first. Correct answer
  3. CPython evaluates elif conditions only when no else clause follows the if block.
  4. DThe elif condition must use >= instead of >, otherwise it can never become true.

Answer and explanation: Branches are tested from top to bottom and only the first true one runs; any x greater than 50 already satisfies x > 10, so the huge branch is unreachable and the stricter test should come first. elif runs when earlier conditions are false, not when they fail with an error, the comparison operator is not the issue, and an else clause is optional and unrelated.

Question 4 of 10, Control Flow: Conditional Blocks and Loops

A countdown loop is written as shown. What happens when it runs? n = 5 while n: n -= 2 print(n)

  1. AIt prints 3, 1 and then stops, because negative numbers are treated as False.
  2. BIt never stops, because n goes 3, 1, -1, -3 and never becomes exactly 0. Correct answer
  3. CIt prints 3 and 1 only, because the loop stops once n drops to an odd number.
  4. DIt raises a TypeError, because an integer cannot be used as a loop condition.

Answer and explanation: The condition while n is false only when n is exactly 0; stepping by 2 from 5 skips over 0, so the loop runs forever with ever more negative values. Negative integers are truthy, oddness has nothing to do with the condition, and integers are valid conditions, so the other explanations are wrong. A safer condition would be while n > 0.

Question 5 of 10, Data Collections: Lists, Tuples, Sets, Dictionaries, and Strings. Choose 2.

A junior developer is deciding between tuples and lists for storing records. Which two statements are correct? (Choose two.)

  1. ATuples can be grown in place with append(), which lists do not provide as a method.
  2. BTuple literals use square brackets, while list literals are written with parentheses.
  3. CA tuple whose elements are all hashable can be a dictionary key, but a list cannot. Correct answer
  4. DA tuple may only store elements that all share exactly the same data type as each other.
  5. EAssigning to t[0] when t is a tuple raises a TypeError because tuples are immutable. Correct answer

Answer and explanation: Tuples are immutable, which is why item assignment fails with TypeError and why a tuple of hashable values can serve as a dictionary key while a mutable list cannot. The bracket styles are reversed in the distractor (lists use [] and tuples use ()), append() exists on lists but not on tuples, and both types can mix data types freely.

Question 6 of 10, Data Collections: Lists, Tuples, Sets, Dictionaries, and Strings

A form handler tries to clean up a name typed with extra spaces. What does the final line print? name = " ada lovelace " name.strip() name = name.title() print(name.startswith("Ada"), len(name))

  1. ATrue 15
  2. BFalse 15 Correct answer
  3. CTrue 12
  4. DFalse 12

Answer and explanation: String methods never modify the original string; strip() returns a new string that is thrown away here, so the leading and trailing spaces stay and the length remains 15. Because the string still begins with two spaces, startswith('Ada') is False even after title() capitalises each word. A length of 12 or a True result assumes strip() changed name in place.

Question 7 of 10, Data Collections: Lists, Tuples, Sets, Dictionaries, and Strings

A tuple is built by concatenation and then repeated. What is printed? t = (1, 2) + (3,) print(t * 2, len(t))

  1. A(2, 4, 6) 3
  2. B(1, 2, 3, 1, 2, 3) 3 Correct answer
  3. C(1, 2, 3, 1, 2, 3) 6
  4. D(1, 2, 3) 6

Answer and explanation: + joins two tuples into the new tuple (1, 2, 3), and * 2 repeats its elements; neither operation changes t, so its length stays 3. Element-wise doubling is not what * does for sequences, the length printed is that of t rather than of the repeated result, and t * 2 does build a new six-element tuple instead of leaving the values unchanged.

Question 8 of 10, Functions and Exceptions

What is the output of the following code? values = ["10", "x", "0"] for v in values: try: print(10 // int(v), end=";") except ValueError: print("V", end=";") except ZeroDivisionError: print("Z", end=";")

  1. A1;Z;V;
  2. B1;V;Z; Correct answer
  3. C1;V;
  4. D1;V;V;

Answer and explanation: int('10') succeeds and 10 // 10 prints 1. int('x') raises ValueError, handled by the first except branch, and int('0') succeeds but 10 // 0 raises ZeroDivisionError, handled by the second branch. The loop continues after each handled exception, so it does not stop after V, and the two exception types are matched by their own branches rather than swapped or merged.

Question 9 of 10, Functions and Exceptions

A summing helper accepts any number of positional arguments. What is printed? def total(*nums): s = 0 for n in nums: s += n return s print(total(), total(4, 5, 6))

  1. A0 6
  2. BNone 15
  3. C0 15 Correct answer
  4. DIt raises a TypeError

Answer and explanation: *nums collects the arguments into a tuple, which is simply empty when nothing is passed, so the first call returns the initial sum 0. The second call iterates over (4, 5, 6) and returns 15. The function always reaches its return statement, it adds all values rather than returning the last one, and calling it with no arguments is allowed.

Question 10 of 10, File Handling and Module Imports

Why do Python developers usually open files with a with statement, as in with open('data.txt') as f:?

  1. AThe file is locked so that no other process can open it until the block is left.
  2. BThe whole file is loaded into memory at once, so every later read becomes faster.
  3. CThe file is opened in binary mode, which avoids newline conversion on all platforms.
  4. DThe file is closed automatically when the block ends, even if an exception occurs. Correct answer

Answer and explanation: The with statement uses the file object as a context manager, guaranteeing that close() runs when the block exits, whether normally or because of an exception. It does not change the mode (text is still the default), does not read the file eagerly, and does not apply any operating-system lock.