Day 4: Geometric Distribution I

Objective

In this challenge, we learn about geometric distributions. Check out the Tutorial tab for learning materials!

Task

The probability that a machine produces a defective product is . What is the probability that the defect is found during the inspection?

Input Format

The first line contains the respective space-separated numerator and denominator for the probability of a defect, and the second line contains the inspection we want the probability of being the first defect for:

1 3
5

If you do not wish to read this information from stdin, you can hard-code it into your program.

Output Format

Print a single line denoting the answer, rounded to a scale of decimal places (i.e., format).


In [1]:
def neg_bernoulli(n, p):
    return p * (1-p)**(n-1)

In [12]:
defective_prob = 1 / 3.0
inspection = 5

In [14]:
round(neg_bernoulli(inspection, defective_prob), 3)


Out[14]:
0.066

In [16]:
neg_bernoulli(12/100.0, 100)


Out[16]:
(-1.6301200434487646-0.6454101829039246j)

In [ ]: