Certified Entry-Level Python Programmer (PCEP-30-02) — Question 37
The following statement ...
assert x == 0
Answer options
- A. will stop the program if x is equal to 0.
- B. has no effect.
- C. is erroneous.
- D. will stop the program if x is not equal to 0.
Correct answer: D
Explanation
The correct answer is D because the 'assert' statement is used to enforce that a condition holds true; if it does not, it raises an AssertionError, thus stopping the program. Option A is incorrect because if x is 0, the assertion passes and does not stop the program. Options B and C are also wrong as the statement has an effect and is syntactically correct.