The box contains 10 white balls and 10 black balls. 3 balls are drawn one by one from the box without replacement.
What is the probability that third ball is white given that the first two are white?
My solution:
A - the third ball is white
B - the first two balls are white
The wanted probability is the conditional probability
$\Pr(A|B) = \frac{\Pr(A\cap B)}{\Pr(B)}$
$\Pr(A\cap B) = \frac{10\cdot 9\cdot 8}{20\cdot 19\cdot 18}$ - here I'm choosing 3 white balls and dividing by the total number of ways to choose 3 balls
$\Pr(B) = \frac{10\cdot 9\cdot 18}{20\cdot 19\cdot 18}$ - here I'm choosing 2 white balls and third - any of 18 remaining and dividing by the total number of ways to choose 3 balls
Then $\Pr(A|B) = \frac{8}{18} = \frac{4}{9} = 0.\overline{4}$
In order to ensure that this is correct solution I've done a simulation of the process described in the task. The code is as follows (Python):
import random
def ex():
#make a list with 10 "w"'s and 10 "b"'s
balls = ['w']*10 + ['b']*10
#pop three random elements from the list
a = balls.pop(random.randint(0, len(balls)-1))
b = balls.pop(random.randint(0, len(balls)-1))
c = balls.pop(random.randint(0, len(balls)-1))
if a == b == 'w':
return c == 'w'
return 0
exps = 10**5
sucs = 0
for i in range(exps):
sucs += ex()
print(sucs / exps)
The simulation gives 0.10509 which is far from $\frac{4}{9}$.
What is wrong and where?
The probability is obviously $\frac{8}{18}$, yes.
The problem with your code is that it will return a 'success' if and only if all three balls are white, i.e. you are calculating $P(W1 \land W2 \land W3)$ (which is $\frac{10}{20} \cdot \frac{9}{19} \cdot \frac{8}{18} \approx 0.10526$ so that coincides with what you experimentally found).
However, you should be calculating $P(W3|W1 \land W2)$
So, you need to count how many times you get $a==b== \ 'w'$ (which out of $100,000$ trials should be about $\frac{10}{20} \cdot \frac{9}{19} \cdot 10^5 \approx 23,684$ times) and out of those how many times you get $c== \ 'w'$