Bird
0
0

What is wrong with this code?

medium📝 Debug Q14 of 15
NumPy - Creating Arrays
What is wrong with this code?
import numpy as np
arr = np.arange(5, 2, 1)
print(arr)
AIt raises a ValueError
BIt produces an empty array
CIt produces [5, 4, 3]
DIt produces [2, 3, 4, 5]
Step-by-Step Solution
Solution:
  1. Step 1: Analyze start, stop, and step values

    Start=5, stop=2, step=1 means counting up from 5 to less than 2, which is impossible.
  2. Step 2: Understand np.arange behavior

    Since step is positive but start > stop, no values satisfy condition, so result is empty array.
  3. Final Answer:

    It produces an empty array -> Option B
  4. Quick Check:

    Positive step with start > stop gives empty array [OK]
Quick Trick: Positive step needs start < stop to produce values [OK]
Common Mistakes:
  • Expecting reversed array without negative step
  • Thinking it raises error
  • Confusing start and stop order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes