Challenge: Day 4: Normal Distribution #2
Subdomeniu: Probability (probability)
Scor cont: 5.0 / 5
Submission status: Accepted
Submission score: 1.0
Submission ID: 464717923
Limbaj: python3
Link challenge: https://www.hackerrank.com/challenges/normal-distribution-2/problem
Cerinta
**Objective** <br>
In this challenge, we practice solving problems with normally distributed variables.
**Task** <br>
In a certain plant, the time taken to assemble a car is a random variable having a normal distribution with a mean of $20$ hours and a standard deviation of $2$ hours. What is the probability that a car can be assembled at this plant in:
1. Less than $19.5$ hours?
2. Between $20$ and $22$ hours?
Output Format
Your output must be a floating point/decimal number, correct to a scale of $3$ decimal places. You can submit solutions in either of the $2$ following ways:
1. Solve the problem manually and submit your result as *Plain Text*. In the text box below, enter $2$ lines of floating point/decimal numbers.
2. Submit an *R* or *Python* program, which uses the above parameters (hard-coded), and computes the answer.
Your answer should resemble something like:
0.123
0.456
(This is **NOT** the answer, just a demonstration of the answering format.)
Cod sursa
# Enter your code here. Read input from STDIN. Print output to STDOUT
import math
def get_function(x):
mu = 20
sig = 2
gaussian_func = (1 / (sig * math.sqrt(2 * math.pi))) * math.exp(-((x - mu) ** 2) / (2 * sig ** 2))
return gaussian_func
start_value = 12
end_value = 28
step = 0.0001
x = [start_value + i * step for i in range(int((end_value - start_value) / step) + 1)]
y = 0
y1 = 0
y2 = 0
for i in range(len(x)):
y += get_function(x[i]) * step
if x[i] < 19.5:
y1 += get_function(x[i]) * step
if 20 < x[i] < 22:
y2 += get_function(x[i]) * step
result1 = int((y1 / y) * 1000) / 1000
result2 = int((y2 / y) * 1000) / 1000
print(str(result1))
print(str(result2))
HackerRank Probability – Day 4: Normal Distribution #2
