Consider a real-valued random variable, X. The cumulative distribution function of X (or just the distribution function of X) evaluated at x is the probability that X will take a value less than or equal to x:
FX(x)=P(X≤x)
Also,
P(a≤X≤b)=P(a<X<b)=FX(b)−FX(a)
The cumulative distribution function for a function with normal distribution is:
Task
In a certain plant, the time taken to assemble a car is a random variable, X, having a normal distribution with a mean of hours and a standard deviation of 2 hours. What is the probability that a car can be assembled at this plant in:
Less than 19.5 hours?
Between 20 and 22 hours?
import mathmean, std =20,2cdf =lambdax: 0.5* (1+ math.erf((x - mean) / (std * (2**0.5))))# Less than 19.5print('{:.3f}'.format(cdf(19.5)))# Between 20 and 22print('{:.3f}'.format(cdf(22) -cdf(20)))
Task
The final grades for a Physics exam taken by a large group of students have a mean of μ=70 and a standard deviation of σ=10. If we can approximate the distribution of these grades by a normal distribution, what percentage of the students:
Scored higher than 80 (i.e., have a grade>80)?
Passed the test (i.e., have a grade≥60)?
Failed the test (i.e., have a grade<60)?
import mathdefarg_erf(x,u,o):return (x-u)/(o * math.sqrt(2))defF(x,arg_x):return0.5* ( 1+ math.erf(arg_x) )u, o =input().split()# u = 70, o = 10u, o =float(u),float(o)a =float(input())# a = 80b =float(input())# b = 60arg_a =arg_erf(a, u, o)arg_b =arg_erf(b, u, o)first_ans = (1-F(a, arg_a))second_ans = (1-F(b, arg_b))third_ans =F(b, arg_b)print(round(first_ans*100.0, 2))print(round(second_ans*100.0, 2))print(round(third_ans*100.0, 2))