Probability of A AND B Practice Problem
This data science coding problem helps you practice Probability Fundamentals, probability of a and b, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Probability Fundamentals.
- Problem ID: 223
- Problem key: 223-probability-of-a-and-b
- URL: https://datacrack.app/solve/223-probability-of-a-and-b
- Difficulty: easy
- Topic: Probability Fundamentals
- Module: Probability
Problem Statement
# 🧩 Probability of A AND B
---
### 🎯 Goal
Calculate the probability that event $A$ and event $B$ both happen.
---
### 📖 Introduction
In probability, **AND** means intersection.
The intersection of two events is written as:
$$
A \cap B
$$
Read this as:
```text
A and B
```
It contains only outcomes that are in both events.
For one die roll:
$$
A=\{2,4,6\}
$$
$$
B=\{5,6\}
$$
Then:
$$
A \cap B = \{6\}
$$
Only `6` is both even and greater than 4.
---
### 📥 Input
- `sample_space`: all possible outcomes.
- `event_a`: outcomes in event $A$.
- `event_b`: outcomes in event $B$.
### 📤 Output
- Return $P(A \cap B)$ rounded to 6 decimals.
---
### 💻 Task
Implement `intersection_probability(sample_space, event_a, event_b)`.
---
### 🧩 Starter Code
```python
def intersection_probability(sample_space, event_a, event_b):
sample_space = set(sample_space)
event_a = set(event_a)
event_b = set(event_b)
pass
```
---
### 💡 Example
```python
intersection_probability([1, 2, 3, 4, 5, 6], [2, 4, 6], [5, 6])
```
Expected output:
```python
0.166667
```
---
### ⚠️ Common Mistakes
- Using **OR** instead of **AND**.
- Including outcomes that appear in only one event instead of keeping only outcomes shared by both events.
- Assuming two events must always share an outcome; sometimes $A \cap B$ is empty, so the probability is $0$.
Starter Code
def intersection_probability(sample_space, event_a, event_b):
sample_space = set(sample_space)
event_a = set(event_a)
event_b = set(event_b)
pass