Here’s a challenging probability problem with a $Python$ solution and a graphical visualization:
Problem
A factory produces items that pass through two quality control tests: Test $A$ and Test $B$.
The probabilities are as follows:
- The probability of passing Test $A$ is $( P(A) = 0.7 )$.
- The probability of passing Test $B$ is $( P(B) = 0.8 )$.
- The probability of passing both tests is $( P(A \cap B) = 0.6 )$.
An item is selected at random.
Let $( X )$ denote the number of tests the item passes.
Find and visualize the probability mass function ($PMF$) of $( X )$, i.e., the probabilities of passing $0$, $1$, or $2$ tests.
Solution Explanation
1. Definitions and Relationships:
- $ P(X = 0) $: Probability of failing both tests.
$ P(X = 0) = 1 - P(A \cup B) $, where $ P(A \cup B) = P(A) + P(B) - P(A \cap B) $. - $ P(X = 1) $: Probability of passing exactly one test.
$ P(X = 1) = P(A) + P(B) - 2P(A \cap B) $. - $ P(X = 2) $: Probability of passing both tests.
$ P(X = 2) = P(A \cap B) $.
2. PMF:
The $PMF$ of $( X )$ is:
$$
P(X = k) \quad \text{for } k \in {0, 1, 2}.
$$
3. Visualization:
We will plot the $PMF$ as a bar chart.
Python Implementation
1 | import matplotlib.pyplot as plt |
Explanation of Code
- PMF Calculation:
- Using set relationships to calculate $ P(X = 0) $, $ P(X = 1) $, and $ P(X = 2) $.
- Bar Chart:
- Bar heights represent probabilities for $ X = 0, 1, 2 $.
- Labels and annotations make the graph interpretable.
Expected Output

Text:
1
2
3
4PMF:
P(X = 0) = 0.10
P(X = 1) = 0.30
P(X = 2) = 0.60Graph:
- A bar chart with $( X = 0, 1, 2 )$ on the x-axis.
- Heights correspond to $( P(X = 0) )$, $( P(X = 1) )$, $( P(X = 2) )$.
- $( P(X = 2) )$ is the highest due to the significant overlap between Test $A$ and Test $B$.








