Bird
Raised Fist0
SciPydata~20 mins

Binomial distribution in SciPy - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Binomial Distribution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Binomial PMF Calculation
What is the output of this code that calculates the probability of exactly 3 successes in 10 trials with success probability 0.5 using scipy's binom.pmf?
SciPy
from scipy.stats import binom
result = binom.pmf(3, 10, 0.5)
print(round(result, 4))
A0.5000
B0.2051
C0.1172
D0.2500
Attempts:
2 left
💡 Hint
Recall that binom.pmf(k, n, p) gives the probability of k successes in n trials with success probability p.
❓ data_output
intermediate
2:00remaining
Number of Trials with Probability Above Threshold
Using scipy's binom.pmf, how many values of k (from 0 to 10) have a probability greater than 0.1 for n=10 and p=0.3?
SciPy
from scipy.stats import binom
probabilities = binom.pmf(range(11), 10, 0.3)
count = sum(p > 0.1 for p in probabilities)
print(count)
A5
B3
C4
D6
Attempts:
2 left
💡 Hint
Calculate probabilities for k=0 to 10 and count how many exceed 0.1.
❓ visualization
advanced
3:00remaining
Identify the Correct Binomial PMF Plot
Which option shows the correct plot of the binomial PMF for n=5 and p=0.6?
SciPy
import matplotlib.pyplot as plt
from scipy.stats import binom
import numpy as np

k = np.arange(0, 6)
pmf = binom.pmf(k, 5, 0.6)
plt.bar(k, pmf)
plt.xlabel('Number of successes')
plt.ylabel('Probability')
plt.title('Binomial PMF for n=5, p=0.6')
plt.show()
AA bar chart with highest bar at k=0 and probabilities summing to more than 1
BA line chart with decreasing values from k=0 to k=5
CA scatter plot with random points not matching binomial probabilities
DA bar chart with highest bar at k=3 and probabilities summing to 1
Attempts:
2 left
💡 Hint
Binomial PMF bars should sum to 1 and peak near np (here 5*0.6=3).
🧠 Conceptual
advanced
2:00remaining
Effect of Increasing Number of Trials on Binomial Distribution Shape
What happens to the shape of the binomial distribution when the number of trials n increases while keeping the success probability p fixed?
AThe distribution becomes more symmetric and approaches a normal distribution shape
BThe distribution becomes uniform across all outcomes
CThe distribution becomes more skewed to the left
DThe distribution becomes a single spike at k=0
Attempts:
2 left
💡 Hint
Think about the Central Limit Theorem and how binomial behaves for large n.
🔧 Debug
expert
2:00remaining
Identify the Error in Binomial PMF Calculation Code
What error does this code produce when trying to calculate the binomial PMF for k=3, n=10, p=0.5? from scipy.stats import binom result = binom.pmf(3, 0.5, 10) print(result)
SciPy
from scipy.stats import binom
result = binom.pmf(3, 0.5, 10)
print(result)
AValueError because probability p is out of range
BTypeError because parameters are in wrong order
CSyntaxError due to missing parentheses
DNo error, outputs correct probability
Attempts:
2 left
💡 Hint
Check the order of parameters for binom.pmf(k, n, p).

Practice

(1/5)
1. What does the binomial distribution model in data science?
easy
A. The relationship between two continuous variables
B. The number of successes in a fixed number of independent trials with the same success probability
C. The average value of a continuous variable
D. The total sum of all outcomes in a dataset

Solution

  1. Step 1: Understand the binomial distribution concept

    The binomial distribution counts how many times an event happens in a fixed number of tries, where each try has the same chance of success.
  2. Step 2: Match the description to the options

    The number of successes in a fixed number of independent trials with the same success probability correctly describes this as the number of successes in fixed independent trials with the same success chance.
  3. Final Answer:

    The number of successes in a fixed number of independent trials with the same success probability -> Option B
  4. Quick Check:

    Binomial distribution = count of successes [OK]
Hint: Binomial counts successes in fixed tries with same chance [OK]
Common Mistakes:
  • Confusing binomial with normal distribution
  • Thinking it models averages or sums
  • Mixing up independent trials with dependent events
2. Which of the following is the correct way to import the binomial distribution function from scipy.stats?
easy
A. import binom from scipy.stats
B. import scipy.binomial as binom
C. from scipy.stats import binom
D. from scipy import binomial

Solution

  1. Step 1: Recall the correct import syntax for scipy.stats binomial

    The binomial distribution is accessed via scipy.stats as 'binom', so the correct import is 'from scipy.stats import binom'.
  2. Step 2: Check each option's syntax

    from scipy.stats import binom matches the correct Python import syntax. Options A, B, and C are invalid Python import statements or incorrect module names.
  3. Final Answer:

    from scipy.stats import binom -> Option C
  4. Quick Check:

    Correct import = from scipy.stats import binom [OK]
Hint: Use 'from scipy.stats import binom' to import binomial [OK]
Common Mistakes:
  • Using wrong module names like scipy.binomial
  • Incorrect import syntax like 'import binom from ...'
  • Forgetting to import from scipy.stats
3. What is the output of this code snippet?
from scipy.stats import binom
n, p = 5, 0.4
prob = binom.pmf(3, n, p)
print(round(prob, 3))
medium
A. 0.230
B. 0.345
C. 0.200
D. 0.410

Solution

  1. Step 1: Understand binom.pmf parameters

    binom.pmf(k, n, p) gives the probability of exactly k successes in n trials with success chance p. Here, k=3, n=5, p=0.4.
  2. Step 2: Calculate binomial probability for k=3

    Using the binomial formula or scipy, the probability is about 0.2304, rounded to 0.230.
  3. Final Answer:

    0.230 -> Option A
  4. Quick Check:

    binom.pmf(3,5,0.4) ≈ 0.230 [OK]
Hint: Use binom.pmf(k,n,p) for exact success probability [OK]
Common Mistakes:
  • Confusing pmf with cdf
  • Mixing up parameters order
  • Rounding incorrectly
4. Identify the error in this code snippet:
from scipy.stats import binom
n, p = 10, 0.3
prob = binom.pmf(n, 10, p)
print(prob)
medium
A. The first argument to binom.pmf should be the number of successes, not total trials
B. The probability p should be an integer
C. The import statement is incorrect
D. The print statement is missing parentheses

Solution

  1. Step 1: Check binom.pmf argument order

    binom.pmf(k, n, p) expects k = number of successes, n = number of trials, p = success probability.
  2. Step 2: Analyze the code arguments

    Here, the first argument is n=10, which is total trials, not the number of successes. This is incorrect usage.
  3. Final Answer:

    The first argument to binom.pmf should be the number of successes, not total trials -> Option A
  4. Quick Check:

    binom.pmf(k,n,p) needs k successes first [OK]
Hint: First arg to pmf is successes, not total trials [OK]
Common Mistakes:
  • Swapping k and n arguments
  • Using integer for probability p
  • Incorrect import or print syntax
5. You want to find the probability of getting at most 2 successes in 8 trials with success chance 0.5 using scipy. Which code snippet correctly calculates this cumulative probability?
hard
A. binom.cdf(8, 2, 0.5)
B. binom.pmf(2, 8, 0.5)
C. binom.sf(2, 8, 0.5)
D. binom.cdf(2, 8, 0.5)

Solution

  1. Step 1: Understand cumulative probability for 'at most' successes

    To find probability of at most 2 successes, use cumulative distribution function (cdf) up to 2.
  2. Step 2: Match correct function and parameters

    binom.cdf(2, 8, 0.5) correctly computes P(X ≤ 2) for n=8, p=0.5. Other options either use pmf (exact), sf (survival function), or wrong parameter order.
  3. Final Answer:

    binom.cdf(2, 8, 0.5) -> Option D
  4. Quick Check:

    Use binom.cdf(k,n,p) for P(X ≤ k) [OK]
Hint: Use binom.cdf for cumulative probability up to k [OK]
Common Mistakes:
  • Using pmf instead of cdf for cumulative
  • Swapping n and k parameters
  • Using survival function sf for 'at most' instead of 'more than'
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard