Non-mutually Exclusive Events - Python Example

Rumman Ansari   Software Engineer   2023-02-23   204 Share
☰ Table of Contents

Table of Content:


Not Mutually Exclusive

The events are not mutually exclusive: If the events are not mutually exclusive, they may have some outcomes in common. In this case, the probability of the union of the events is the sum of the probabilities of the individual events minus the probability of the intersection of the events.

$$P(A \cup B) = P(A) + P(B) - P(A \cap B)$$

Example:

Question:

If a 6-sided dice numbered 1 to 6 is rolled, find the probability of getting either an even or prime number.


Solution:

Sample Space={1,2,3,4,5,6}

Let A denote getting an even number.

A = {2,4,6}

Let B denote getting a prime number.

B = {2,3,5}

Let event \(A\) be rolling an even number and event \(B\) be rolling a prime number. Then,

$$A = {2, 4, 6}$$ $$B = {2, 3, 5}$$

$$A \cup B = {2, 3, 4, 5, 6}$$

So, the probability of rolling either an even or prime number is:

$$P(A \cup B) = P({2, 3, 4, 5, 6}) = \frac{5}{6}$$

Therefore, the probability of getting either an even or prime number when rolling a 6-sided dice is \( \frac{5}{6}\) or approximately \(0.83\) .


Python Code


prob_getting_even=3/6
prob_getting_prime=3/6
prob_even_and_prime=1/6
prob_even_or_prime=0.5+0.5-0.16
print(prob_even_or_prime)

Output:


0.83

Mutually Exclusive Events - Example

Question:

In a deck of cards, what is the probability of getting either a King or Queen card.

Note: A card cannot be a King and a Queen at the same time. They are mutually exclusive events.


Solution:

P(King)=1/13 P(Queen)=1/13

Python Code


prob_getting_king=1/13
prob_getting_queen=1/13
prob_king_or_queen=2/13
print(prob_king_or_queen)

Output:


0.153