Conditional Probability Formula Practice Problem
This data science coding problem helps you practice Conditional Probability & Bayes, conditional probability formula, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Conditional Probability & Bayes.
- Problem ID: 230
- Problem key: 230-conditional-probability-formula
- URL: https://datacrack.app/solve/230-conditional-probability-formula
- Difficulty: easy
- Topic: Conditional Probability & Bayes
- Module: Probability
Problem Statement
# 🧩 Conditional Probability Formula
---
### 🎯 Goal
Calculate conditional probability using the formal formula.
---
### 📖 Introduction
In the previous problem, you learned the meaning of:
$$
P(A \mid B)
$$
It means:
```text
Among the outcomes inside B, what proportion also belong to A?
```
Now we write that idea using probabilities.
The outcomes that are inside both $A$ and $B$ are written as:
$$
A \cap B
$$
The condition $B$ becomes the restricted sample space.
So the conditional probability formula is:
$$
P(A \mid B)=\frac{P(A\cap B)}{P(B)}
$$
This problem gives you $P(A\cap B)$ and $P(B)$ directly.
---
### 📥 Input
- `p_intersection`: probability of $A \cap B$.
- `p_b`: probability of event $B$.
Assume `p_b` is greater than 0.
### 📤 Output
- Return $P(A \mid B)$ rounded to 6 decimals.
---
### 💻 Task
Implement `conditional_probability_formula(p_intersection, p_b)`.
Use the provided probabilities to calculate:
$$
P(A \mid B)
$$
---
### 🧩 Starter Code
```python
def conditional_probability_formula(p_intersection, p_b):
pass
```
---
### 💡 Example
```python
conditional_probability_formula(0.2, 0.5)
```
The function should return the conditional probability as a decimal rounded to 6 decimals.
---
### ⚠️ Common Mistakes
- Dividing by $P(A)$ instead of $P(B)$.
- Forgetting that the condition after the vertical bar is the denominator.
- Treating $P(A\cap B)$ and $P(A \mid B)$ as the same thing.
Starter Code
def conditional_probability_formula(p_intersection, p_b):
pass