1
votes

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!

2

2 Answers

1
votes

By my calculations 10/12 is correct. @Thrustmaster listed the possibilites, but without their probability of occurrence. Taking probability of occurrence into account there are 30 desirable outcomes, out of 36 possible rolls, which is 5/6 (or 10/12 as you have it).

Edit: I see you updated your question to change the problem. In this case, yes, 2/3 is correct.

1
votes

The theoretical answer would be:

   1  2  3  4  5  6
   ________________
1 |2  3  4  5  6  7
2 |3  4  5  6  7  8
3 |4  5  6  7  8  9
4 |5  6  7  8  9 10
5 |6  7  8  9 10 11
6 |7  8  9 10 11 12

Total favorable outputs: [(1,1),(3,1),(1,3), (1,5) .....(7,1)..(6,6)] : total 24
All possible outputs: 36

Theoretical probability: 2/3

I tried with thing(1000000), the output was 0.667812, which is close enough.. :)