I was given a probability problem, and I wrote a script to test it.
Two unbiased dice are thrown once and the total score is observe. Find de probabiity that: a) The total score is even or greater than 7
I wrote the following script in Python, and it should give me the probability of "A" correct.
import random
def thing(trials):
i = 0
number = 0
while i < trials:
answer1 = random.choice([1, 2, 3, 4, 5, 6])
answer2 = random.choice([1, 2, 3, 4, 5, 6])
if (answer1 + answer2)%2 == 0:
number += 1.0
elif (answer1 + answer2) > 7:
number += 1.0
i += 1
print number/i
This gives me 2/3 as the answer, which is correct. Thanks!