Probability of A OR B Practice Problem
This data science coding problem helps you practice Probability Fundamentals, probability of a or b, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Probability Fundamentals.
- Problem ID: 222
- Problem key: 222-probability-of-a-or-b
- URL: https://datacrack.app/solve/222-probability-of-a-or-b
- Difficulty: easy
- Topic: Probability Fundamentals
- Module: Probability
Problem Statement
# 🧩 Probability of A OR B
---
### 🎯 Goal
Calculate the probability that event $A$ happens **or** event $B$ happens.
---
### 📖 Introduction
In probability, **OR** means union.
The union of two events is written as:
$$
A \cup B
$$
Read this as:
```text
A or B or both
```
For one die roll:
$$
\Omega=\{1,2,3,4,5,6\}
$$
Let:
$$
A=\{2,4,6\}
$$
and:
$$
B=\{5,6\}
$$
Then:
$$
A \cup B = \{2,4,5,6\}
$$
The outcome `6` belongs to both events, but it is counted only once in the union.
---
### 📥 Input
- `sample_space`: all possible outcomes.
- `event_a`: outcomes in event $A$.
- `event_b`: outcomes in event $B$.
### 📤 Output
- Return $P(A \cup B)$ rounded to 6 decimals.
---
### 💻 Task
Implement `union_probability(sample_space, event_a, event_b)`.
---
### 🧩 Starter Code
```python
def union_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
union_probability([1, 2, 3, 4, 5, 6], [2, 4, 6], [5, 6])
```
Expected output:
```python
0.666667
```
---
### ⚠️ Common Mistakes
- Counting the overlap twice.
Starter Code
def union_probability(sample_space, event_a, event_b):
sample_space = set(sample_space)
event_a = set(event_a)
event_b = set(event_b)
pass