Bird
Raised Fist0
SciPydata~20 mins

Normal distribution in SciPy - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What does the normal distribution model in data science?
easy
A. Data with no variation
B. Data with only positive values
C. Data sorted in ascending order
D. Data spread around an average value

Solution

  1. Step 1: Understand the normal distribution concept

    The normal distribution describes how data points are spread around a central average (mean).
  2. Step 2: Identify the correct description

    Among the options, only data spread around an average matches the normal distribution's purpose.
  3. Final Answer:

    Data spread around an average value -> Option D
  4. Quick Check:

    Normal distribution = data around average [OK]
Hint: Normal distribution centers data around mean [OK]
Common Mistakes:
  • Thinking normal distribution only has positive values
  • Confusing normal distribution with sorted data
  • Assuming no variation in normal distribution
2. Which of the following is the correct way to import the normal distribution functions from scipy.stats?
easy
A. import scipy.norm
B. from scipy.stats import norm
C. from scipy import normal
D. import stats.norm

Solution

  1. Step 1: Recall scipy.stats import syntax

    The normal distribution functions are in scipy.stats under the name 'norm'.
  2. Step 2: Match correct import statement

    Only 'from scipy.stats import norm' correctly imports the normal distribution functions.
  3. Final Answer:

    from scipy.stats import norm -> Option B
  4. Quick Check:

    Correct import = from scipy.stats import norm [OK]
Hint: Use 'from scipy.stats import norm' to access normal distribution [OK]
Common Mistakes:
  • Using 'import scipy.norm' which does not exist
  • Trying 'from scipy import normal' which is incorrect
  • Importing 'stats.norm' without scipy prefix
3. What is the output of this code?
from scipy.stats import norm
result = norm.cdf(0, loc=0, scale=1)
print(round(result, 2))
medium
A. 1.00
B. 0.00
C. 0.50
D. 0.84

Solution

  1. Step 1: Understand norm.cdf at mean

    norm.cdf(x, loc, scale) gives the probability data is less than x. At x=0 with mean=0, scale=1, it is the 50th percentile.
  2. Step 2: Calculate and round the result

    The cumulative probability at mean is 0.5, rounding to 2 decimals gives 0.50.
  3. Final Answer:

    0.50 -> Option C
  4. Quick Check:

    norm.cdf(mean) = 0.5 [OK]
Hint: CDF at mean of normal = 0.5 [OK]
Common Mistakes:
  • Confusing PDF with CDF values
  • Expecting 0 or 1 instead of 0.5 at mean
  • Rounding errors ignoring decimals
4. Find the error in this code snippet:
from scipy.stats import norm
prob = norm.pdf(1, mean=0, scale=1)
print(prob)
medium
A. Parameter 'mean' should be 'loc'
B. Missing import statement
C. norm.pdf does not exist
D. scale must be an integer

Solution

  1. Step 1: Check parameter names for norm.pdf

    norm.pdf uses 'loc' for mean, not 'mean'. Using 'mean' causes an error.
  2. Step 2: Identify correct parameter

    Replace 'mean=0' with 'loc=0' to fix the code.
  3. Final Answer:

    Parameter 'mean' should be 'loc' -> Option A
  4. Quick Check:

    Use loc for mean in norm functions [OK]
Hint: Use 'loc' not 'mean' for normal distribution mean [OK]
Common Mistakes:
  • Using 'mean' instead of 'loc' parameter
  • Assuming norm.pdf is missing
  • Thinking scale must be integer
5. You want to find the probability that a value from a normal distribution with mean 10 and standard deviation 2 is less than 13. Which code correctly calculates this using scipy?
hard
A. norm.cdf(13, loc=10, scale=2)
B. norm.pdf(13, loc=10, scale=2)
C. norm.cdf(10, loc=13, scale=2)
D. norm.sf(13, loc=10, scale=2)

Solution

  1. Step 1: Identify the function for cumulative probability

    To find probability less than a value, use norm.cdf with the value, mean (loc), and std dev (scale).
  2. Step 2: Match parameters to the problem

    Value is 13, mean is 10, std dev is 2, so norm.cdf(13, loc=10, scale=2) is correct.
  3. Final Answer:

    norm.cdf(13, loc=10, scale=2) -> Option A
  4. Quick Check:

    Use norm.cdf(value, loc=mean, scale=std) [OK]
Hint: Use norm.cdf for probability less than a value [OK]
Common Mistakes:
  • Using norm.pdf instead of norm.cdf
  • Swapping loc and value parameters
  • Using norm.sf which gives probability greater than value
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