Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-012

Geometric PMF

Problem

Geometric probability mass function for the number of trials until the first success.

P(X = k) = (1 - p)^(k - 1) * p for k >= 1. Return 0.0 for k < 1.

Hint

Fail k - 1 times, then succeed once.

Test cases

case 1
in: [0.5,1]
expected: 0.5
case 2
in: [0.5,3]
expected: 0.125
case 3
in: [0.2,5]
expected: 0.08192000000000002
case 4
in: [0.5,0]
expected: 0
Starter codePython
def geometric_pmf(p, k):
    # Your code here
    pass

4 test cases · run your code against them in the editor