PCEP-30-02 · Question #246
QUESTION 274 An assertion can be used to:
The correct answer is A. Stop the program when some data have improper values. An assert statement is a debugging tool that tests a condition and immediately raises an AssertionError (halting execution) if the condition evaluates to False - making it ideal for catching improper data values early in development. Option B is wrong because importing modules…
Question
Options
- AStop the program when some data have improper values.
- BImport a module.
- CMake the Programmer more assertive.
How the community answered
(25 responses)- A72% (18)
- B20% (5)
- C8% (2)
Explanation
An assert statement is a debugging tool that tests a condition and immediately raises an AssertionError (halting execution) if the condition evaluates to False - making it ideal for catching improper data values early in development. Option B is wrong because importing modules is handled by the import keyword, which has nothing to do with assertions. Option C is a joke distractor - "assertive" here is wordplay on the keyword name, not a real programming concept.
Memory tip: Think of assert as a guardian - it stands watch over your data and stops the program the moment something looks wrong, like a bouncer who won't let bad values through.
x = -5
assert x > 0, "x must be positive" # Raises AssertionError, stopping the program
Community Discussion
No community discussion yet for this question.