Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
NumPy - Fundamentals
Identify the error in this code:
import numpy as np
arr = np.array(1, 2, 3)
print(arr)
Aprint statement is incorrect
Bnp.array cannot hold integers
Cnp.array requires a single iterable argument
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check np.array argument format

    np.array expects one iterable like a list or tuple, not multiple separate arguments.
  2. Step 2: Identify the error cause

    Passing 1, 2, 3 as separate arguments causes a TypeError.
  3. Final Answer:

    np.array requires a single iterable argument -> Option C
  4. Quick Check:

    np.array needs one iterable [OK]
Quick Trick: Pass a list or tuple inside np.array() [OK]
Common Mistakes:
  • Passing multiple arguments instead of one iterable
  • Thinking np.array can't hold integers
  • Misusing print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes