Bird
0
0

You want to write a pytest test that passes only if variable score is NOT equal to 0 or 100. Which assertion is correct?

hard🚀 Application Q8 of 15
PyTest - Writing Assertions
You want to write a pytest test that passes only if variable score is NOT equal to 0 or 100. Which assertion is correct?
Aassert score != 0 and score != 100
Bassert score == 0 or score == 100
Cassert score != (0 or 100)
Dassert score == 0 and score == 100
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition

    The test should pass if score is neither 0 nor 100.
  2. Step 2: Translate condition to assertion

    Use 'assert score != 0 and score != 100' to ensure score is not equal to either value.
  3. Step 3: Analyze incorrect options

    assert score != (0 or 100) is wrong because '(0 or 100)' evaluates to 0, so it only checks 'score != 0'.
  4. Final Answer:

    assert score != 0 and score != 100 -> Option A
  5. Quick Check:

    Use 'and' to combine multiple inequality checks [OK]
Quick Trick: Combine inequalities with 'and' for multiple conditions [OK]
Common Mistakes:
MISTAKES
  • Using 'or' instead of 'and' for multiple inequalities
  • Misusing 'score != (0 or 100)'
  • Confusing equality and inequality

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes