Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
SciPy - Statistical Functions (scipy.stats) Basics
Identify the error in this code snippet:
from scipy.stats import binom
n, p = 5, 0.4
prob = binom.pmf(n, 3, p)
print(prob)
Apmf function does not exist in scipy.stats.binom
BParameters n and k are swapped in pmf call
CImport statement is incorrect
DProbability p is out of range
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter order in binom.pmf

    The correct order is pmf(k, n, p), but code uses pmf(n, 3, p), swapping n and k.
  2. Step 2: Identify the error

    Swapping n and k causes wrong calculation or error.
  3. Final Answer:

    Parameters n and k are swapped in pmf call -> Option B
  4. Quick Check:

    pmf(k, n, p) order must be correct [OK]
Quick Trick: pmf(k, n, p) order is fixed; swapping causes errors [OK]
Common Mistakes:
MISTAKES
  • Swapping n and k parameters
  • Assuming pmf accepts different order
  • Ignoring parameter meanings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes