Lesson 1 of 15

Sample Spaces & Events

The Language of Chance

A sample space Ω\Omega is the set of all possible outcomes of a random experiment. An event is any subset of Ω\Omega.

Classical probability applies when all outcomes are equally likely:

P(A)=AΩP(A) = \frac{|A|}{|\Omega|}

where A|A| is the number of outcomes in event AA.

# Rolling a fair die
omega = [1, 2, 3, 4, 5, 6]
even  = [2, 4, 6]

p = len(even) / len(omega)
print(round(p, 4))  # 0.5

Set Operations on Events

OperationNotationMeaning
UnionABA \cup BA or B occurs
IntersectionABA \cap BA and B both occur
ComplementAcA^cA does not occur

Your Task

Implement classical_probability(outcomes, event) that returns P(A)=event/outcomesP(A) = |\text{event}| / |\text{outcomes}|, rounded to 4 decimal places.

Pyodide loading...
Loading...
Click "Run" to execute your code.