PCPP 32 10x PCPP Certified Professional Python Programmer 1 · Free Practice Question Medium

Question 4

You are reviewing a script that performs data analysis, and you notice that the code includes a complex conditional statement that spans multiple lines. Here is a snippet of the code:



Which of the following options correctly refactors the code to adhere to PEP 8 guidelines regarding indentation and continuation lines?

  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: D

A.

The condition lines are not consistently aligned, and the block of code under the if statement is indented by 8 spaces instead of 4. This excessive indentation is not compliant with PEP 8 and can reduce readability.

B.

Although the conditions are on separate lines, the alignment is inconsistent. The conditions should align with the first condition after the opening parenthesis for better readability according to PEP 8.

C.

The last condition is placed on the same line as the previous one without proper alignment under the first line’s indentation. This decreases readability and makes it harder to identify each condition.

D.

This option adheres to PEP 8 guidelines. The continuation lines are properly aligned under the opening parenthesis, ensuring clarity and consistency. Each logical continuation line is indented by one level (4 spaces), which enhances readability.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need