← Quiz: Testing Python Code: all 10 questions
Quiz: Testing Python Code · Question 1 of 10
What happens when assert x 0, "x must be positive" runs with x = -2?
What happens when assert x > 0, "x must be positive" runs with x = -2?
- A.Nothing; assert only prints a warning
- B.AssertionError is raised with the message "x must be positive"
- C.ValueError is raised
- D.The program prints "x must be positive" and continues
Answer & explanation
Correct answer: AssertionError is raised with the message "x must be positive"
A false condition raises AssertionError carrying the message.
Can you get the rest right without peeking?
Take the timed Quiz: Testing Python Code quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →