Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q14 of 15
NumPy - Fundamentals
Find the error in this code snippet:
import numpy as np
list1 = [1, 2, 3]
arr1 = np.array(list1)
result = arr1 + '2'
print(result)
Aprint statement syntax error
Bnp.array() is used incorrectly
CCannot add string '2' to NumPy array of integers
Dlist1 should be a tuple
Step-by-Step Solution
Solution:
  1. Step 1: Identify data types involved

    arr1 is an integer array; '2' is a string.
  2. Step 2: Understand operation error

    Adding string to integer array causes a type error in NumPy.
  3. Final Answer:

    Cannot add string '2' to NumPy array of integers -> Option C
  4. Quick Check:

    Type mismatch causes error [OK]
Quick Trick: NumPy arrays need matching data types for math [OK]
Common Mistakes:
  • Thinking np.array() usage is wrong
  • Assuming list must be tuple
  • Believing print syntax is incorrect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes