(November 2010)
A nice puzzle... Read the code below...
import random
def BoolProb(x):
return random.random() < x/100.
SampleSize = 10000000
PositiveTests = 0
PositiveTestAndSick = 0
for i in xrange(0, SampleSize):
sick = BoolProb(0.01)
if sick:
testResultPositive = BoolProb(99)
else:
testResultPositive = BoolProb(1)
if testResultPositive:
PositiveTests += 1
if sick:
PositiveTestAndSick += 1
print "Chance of being sick if test is positive:", \
float(PositiveTestAndSick)/PositiveTests
|
Running the code will give you something like this:
bash$ python ./Am.I.sick.py
Chance of being sick if test is positive: 0.00955057847804
...that is, less than one per cent chance.
|