Multiplication Rule Practice Problem
This data science coding problem helps you practice Conditional Probability & Bayes, multiplication rule, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Conditional Probability & Bayes.
- Problem ID: 233
- Problem key: 233-multiplication-rule
- URL: https://datacrack.app/solve/233-multiplication-rule
- Difficulty: medium
- Topic: Conditional Probability & Bayes
- Module: Probability
Problem Statement
# 🧩 Multiplication Rule
---
### 🎯 Goal
Calculate a joint probability by multiplying a first event probability by a conditional probability.
---
### 📖 Introduction
You learned:
$$
P(A \mid B)=\frac{P(A\cap B)}{P(B)}
$$
Rearranging gives:
$$
P(A\cap B)=P(B)P(A\mid B)
$$
This is the **multiplication rule**.
$P(A\cap B)$ is the probability that **both $A$ and $B$ happen**, also called their **joint probability**.
Why does it work?
- $P(B)$ gives us the probability of being in event $B$.
- Once we are inside $B$, $P(A\mid B)$ gives us the probability of also being in $A$.
So:
$$
P(B)\times P(A\mid B)
$$
gives the probability of being in $B$ **and** in $A$.
That is exactly their intersection, or joint probability:
$$
P(A\cap B)
$$
So multiplying them gives the probability of being in both $A$ and $B$.
We can also start from $A$:
$$
P(A\cap B)=P(A)P(B\mid A)
$$
Both formulas describe the same intersection; they just start from different events.
---
### 📥 Input
- `p_b`: probability that event $B$ happens.
- `p_a_given_b`: probability that event $A$ happens given $B$.
### 📤 Output
- Return $P(A\cap B)$ rounded to 6 decimals.
---
### 💻 Task
Implement `multiplication_rule(p_b, p_a_given_b)`.
Your function should calculate:
$$
P(A\cap B)=P(B)P(A\mid B)
$$
---
### 🧩 Starter Code
```python
def multiplication_rule(p_b, p_a_given_b):
pass
```
---
### 💡 Example
```python
multiplication_rule(0.5, 0.4)
```
Expected output:
```python
0.2
```
---
### ⚠️ Common Mistakes
- Adding the probabilities instead of multiplying them.
- Multiplying by $P(A)$ when the input is $P(A\mid B)$.
- Forgetting that the result is a joint probability for both events happening.
Starter Code
def multiplication_rule(p_b, p_a_given_b):
pass