Day 5: Normal Distribution II

https://www.hackerrank.com/challenges/s10-normal-distribution-2

Objective

In this challenge, we go further with normal distributions. We recommend reviewing the previous challenge's Tutorial before attempting this problem.

Task

The final grades for a Physics exam taken by a large group of students have a mean of m=70 and a standard deviation of stdv = 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 > 80)?
  • Passed the test (i.e., have a >= 60)?
  • Failed the test (i.e., have a < 60)?

Find and print the answer to each question on a new line, rounded to a scale of decimal places.


In [1]:
import math

In [2]:
def cumulative(x, m, stdv):
    return 0.5 * (1 + math.erf((x-m)/ (stdv * math.sqrt(2)) ))

In [3]:
mean = 70
stdv = 10

In [4]:
# gt80 = cumulative(100, mean, stdv) - cumulative(80, mean, stdv)
# gte60 = cumulative(100, mean, stdv) - cumulative(60, mean, stdv)
# lt60 = cumulative(60, mean, stdv)
gt80 = 1 - cumulative(80, mean, stdv)
gte60 = 1 - cumulative(60, mean, stdv)
lt60 = cumulative(60, mean, stdv)

In [5]:
print(round(gt80, 4))
print(round(gte60, 4))
print(round(lt60, 4))


0.1587
0.8413
0.1587

In [ ]: