All problems
Geometric CDF
Problem
Geometric cumulative distribution function for the number of trials until the first success.
P(X <= k) = 1 - (1 - p)^k for k >= 0. Return 0.0 for k < 0.
Hint
Use the complement: all k trials fail with probability (1 - p)^k.
Test cases
case 1
in: [0.5,1]
expected: 0.5
case 2
in: [0.5,3]
expected: 0.875
case 3
in: [0.2,0]
expected: 0
case 4
in: [1,5]
expected: 1
case 5
in: [0.5,-1]
expected: 0
Starter codePython
def geometric_cdf(p, k):
# Your code here
pass5 test cases · run your code against them in the editor