Geometric Distribution: Waiting for the First Success

Probability and StatisticsEasy+10 XP+10

Geometric Distribution: Waiting for the First Success

A Geometric variable counts how many trials it takes to get the first success, when each trial succeeds independently with probability p. k = 1 means success on the very first try.

P(X=k)=(1−p)k−1p,k=1,2,3,…P(X = k) = (1-p)^{k-1} p, \quad k = 1, 2, 3, \dotsP(X=k)=(1−p)k−1p,k=1,2,3,…

Task: write geometric_pmf_mean(p, k) returning [pmf, mean], each rounded to 4 decimal places, where mean = 1/p.

  • k counts trials starting from 1, never 0 — there's no such thing as succeeding on your "zeroth" try.
  • A rarer success (smaller p) pushes the mean number of trials needed higher.

Examples

p = 0.3
k = 3
returns [0.147, 3.3333]
p = 0.5
k = 1
returns [0.5, 2.0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run