Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q14 of 15
SciPy - Statistical Functions (scipy.stats) Basics
Identify the error in the following code snippet:
from scipy.stats import binom
samples = binom.rvs(n=10, p=0.5, size='5')
AParameter 'size' should be an integer, not a string
BParameter 'p' must be greater than 1
CParameter 'n' should be a float, not int
DMissing import for numpy
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter types for rvs

    The size parameter expects an integer or tuple of integers, not a string.
  2. Step 2: Analyze given parameters

    Here, size='5' is a string, which will cause a TypeError.
  3. Final Answer:

    Parameter 'size' should be an integer, not a string -> Option A
  4. Quick Check:

    size must be int, not string [OK]
Quick Trick: Size must be int or tuple, never string [OK]
Common Mistakes:
MISTAKES
  • Passing size as string instead of int
  • Thinking p must be >1 (it's a probability 0-1)
  • Assuming n must be float

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes