Bird
0
0

Identify the error in the following code:

medium📝 Debug Q6 of 15
SciPy - Statistical Functions (scipy.stats) Basics
Identify the error in the following code:
from scipy.stats import norm
samples = norm.rvs(5, size=10)
print(samples)
AMissing scale parameter; loc=5 is interpreted as size
BThe size parameter should be passed as the first argument
CThe mean parameter should be named loc=5
DNo error; code runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the code syntax and parameters

    norm.rvs(5, size=10) passes 5 as positional loc=5, scale defaults to 1, size=10 is keyword.
  2. Step 2: Verify execution

    The code runs correctly, generating 10 samples from Normal(5, 1).
  3. Final Answer:

    No error; code runs correctly -> Option D
  4. Quick Check:

    norm.rvs(5, size=10) valid: loc=5, scale=1 default [OK]
Quick Trick: Positional loc/scale arguments are valid before size [OK]
Common Mistakes:
MISTAKES
  • Misinterpreting positional loc as size
  • Thinking size must be positional first
  • Believing loc must always be named

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes