0
0
SciPydata~20 mins

Normal distribution in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Normal Distribution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of Normal Distribution PDF Calculation
What is the output of this code that calculates the probability density function (PDF) of a normal distribution at x=0 with mean=0 and standard deviation=1?
SciPy
from scipy.stats import norm
result = norm.pdf(0, loc=0, scale=1)
print(round(result, 4))
A0.5000
B0.3989
C1.0000
D0.0000
Attempts:
2 left
💡 Hint
Recall the formula for the normal distribution PDF at the mean.
data_output
intermediate
2:00remaining
Number of Samples within One Standard Deviation
Using scipy, generate 1000 samples from a normal distribution with mean=5 and std=2. How many samples fall between 3 and 7 (within one standard deviation)?
SciPy
import numpy as np
from scipy.stats import norm
samples = norm.rvs(loc=5, scale=2, size=1000, random_state=42)
count = np.sum((samples >= 3) & (samples <= 7))
print(count)
A950
B500
C682
D840
Attempts:
2 left
💡 Hint
Recall the empirical rule for normal distributions.
visualization
advanced
2:30remaining
Plotting Normal Distribution PDF with Different Parameters
Which option produces a plot showing two normal distribution curves: one with mean=0, std=1 and another with mean=2, std=0.5?
SciPy
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
x = np.linspace(-3, 5, 500)
plt.plot(x, norm.pdf(x, 0, 1), label='mean=0, std=1')
plt.plot(x, norm.pdf(x, 2, 0.5), label='mean=2, std=0.5')
plt.legend()
plt.show()
APlots two curves: a wider bell centered at 0 and a narrower bell centered at 2
BPlots two identical curves both centered at 0
CPlots one curve only centered at 1
DRaises a TypeError due to wrong function usage
Attempts:
2 left
💡 Hint
Check the parameters passed to norm.pdf for each curve.
🧠 Conceptual
advanced
1:30remaining
Understanding the Effect of Standard Deviation on Normal Distribution Shape
Which statement correctly describes how increasing the standard deviation affects the shape of a normal distribution?
AThe curve becomes wider and shorter, spreading data over a larger range
BThe curve becomes narrower and taller, concentrating data near the mean
CThe curve shifts to the right without changing shape
DThe curve becomes asymmetric, skewing to one side
Attempts:
2 left
💡 Hint
Think about how spread relates to standard deviation.
🔧 Debug
expert
2:00remaining
Identify the Error in Normal Distribution Sampling Code
What error does this code raise when trying to generate samples from a normal distribution? import numpy as np from scipy.stats import norm samples = norm.rvs(loc=0, scale=-1, size=100) print(samples)
SciPy
import numpy as np
from scipy.stats import norm
samples = norm.rvs(loc=0, scale=-1, size=100)
print(samples)
ARuntimeWarning: invalid value encountered in sqrt
BNo error, prints 100 samples
CTypeError: unsupported operand type(s) for -: 'int' and 'str'
DValueError: scale parameter must be positive
Attempts:
2 left
💡 Hint
Check the scale parameter value passed to norm.rvs.