We have a six sided die, with sides numbered 1 through 6. The probability of first seeing a 1 on the n-th roll decreases as n increases. I want to find the smallest number of rolls such that this probability is less than some given limit.
def probTest(limit):
prob = 1.0
n = 1
while prob > limit:
prob = (1/6)**n
n += 1
return n-1
What is wrong with my code?
The probably of rolling a one on the nth roll is 5/6^(n-1)*1/6, not 1/6^n.
1/6^n is the probability of rolling one on all n rolls.
The first n-1 rolls each have a 5/6 chance of not being one.
The nth roll has a 1/6th chance of being one.
the correct will be: prob = (5.0/6)**(n-1)*1/6.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With