Bird
0
0

This test code has an error:

medium📝 Debug Q14 of 15
Testing Fundamentals - Why Software Testing Matters
This test code has an error:
def test_divide():
    result = 10 / 0
    assert result == 0
    print('Test passed')

What is the error and how to fix it?
AAssertionError; fix by changing assert to result != 0
BSyntaxError; fix by adding colon after function
CNameError; fix by defining result before use
DZeroDivisionError; fix by avoiding division by zero
Step-by-Step Solution
Solution:
  1. Step 1: Identify the error in code

    Dividing by zero causes ZeroDivisionError at runtime.
  2. Step 2: Fix the error

    Avoid dividing by zero to prevent the error.
  3. Final Answer:

    ZeroDivisionError; fix by avoiding division by zero -> Option D
  4. Quick Check:

    Division by zero causes error [OK]
Quick Trick: Division by zero causes error; never divide by zero [OK]
Common Mistakes:
  • Confusing runtime error with syntax error
  • Thinking assertion fails first
  • Ignoring division by zero problem

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes