Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-169

Gambler's Fallacy Sequence Probability

Problem

A gambler believes a tail is due after k heads in a row. Return the actual probability of seeing k heads followed by a tail under independence:

P = p^k * (1 - p).

The probability of the next flip never depends on past flips. Return 0.0 for k < 0.

Hint

Multiply the probabilities of the k heads and the final tail.

Test cases

case 1
in: [0.5,3]
expected: 0.0625
case 2
in: [0.5,0]
expected: 0.5
case 3
in: [0.3,2]
expected: 0.063
case 4
in: [1,5]
expected: 0
Starter codePython
def gamblers_fallacy_probability(p, k):
    # Your code here
    pass

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