🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Nothing; assert only prints a warning
  2. B.AssertionError is raised with the message "x must be positive"
  3. C.ValueError is raised
  4. 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 →