Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
NumPy - Creating Arrays
What is wrong with this code?
import numpy as np
arr = np.arange(10, 5, 1)
print(arr)
AStep must be negative when start > stop
BStart is greater than stop with positive step, so empty array
Cnp.arange cannot have start > stop
DNo error, prints numbers from 10 to 5
Step-by-Step Solution
Solution:
  1. Step 1: Analyze start, stop, and step

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

    np.arange returns an empty array because no values satisfy the condition.
  3. Final Answer:

    Start is greater than stop with positive step, so empty array -> Option B
  4. Quick Check:

    Positive step with start > stop returns empty array [OK]
Quick Trick: Positive step requires start < stop [OK]
Common Mistakes:
  • Expecting reversed array
  • Using wrong step sign
  • Assuming error raised

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes