Bird
0
0

Identify the bug in this code:

medium📝 Debug Q7 of 15
NumPy - Array Operations
Identify the bug in this code:
import numpy as np
arr = np.array([1, 2, 3])
result = arr / 0
print(result)
AArray elements become zero
BCode runs without any warning or error
CDivision by zero causes runtime warning and results in inf or nan
DSyntax error due to division operator
Step-by-Step Solution
Solution:
  1. Step 1: Understand division by zero in NumPy

    Dividing by zero triggers a runtime warning and results in infinity or NaN values.
  2. Step 2: Check expected output

    Elements become inf or nan, not zero or error.
  3. Final Answer:

    Division by zero causes runtime warning and results in inf or nan -> Option C
  4. Quick Check:

    Division by zero = runtime warning with inf/nan [OK]
Quick Trick: Division by zero yields inf or nan with warning [OK]
Common Mistakes:
  • Expecting zero result
  • Expecting syntax error
  • Ignoring runtime warnings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes