Basic Event Probability (Favorable / Total)

Basics
BasicsAxiomsGoogleMetaJane Street

Problem

Given favorable outcomes and total equally likely outcomes (total > 0), implement event_probability(favorable, total) returning favorable / total as a Python float.

Why It Matters: Laplace's classical probability ratio is the starting point for dice, card, sampling, and empirical frequency problems.

Function Signature

def event_probability(favorable: int, total: int) -> float:

Sample Input & Output

Example 1: Rolling an Even Number on a 6-Sided Die

Input:

favorable = 3, total = 6

Expected Output:

0.5

Explanation: 3 even faces (2, 4, 6) out of 6 total faces → 3 / 6 = 0.5.

Example 2: Impossible vs. Certain Event

Input:

favorable = 0, total = 10

Expected Output:

0.0

Explanation: 0 / 10 = 0.0 (similarly 10 / 10 = 1.0).

Constraints & Edge Cases

  • 0 <= favorable <= total, total > 0.
  • Guaranteed 0 <= favorable <= total and total > 0.
  • Return a Python float in [0.0, 1.0].

Constraints & Evaluation Criteria

  • `0 <= favorable <= total`, `total > 0`.

Hints

Python 3
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
favorable=3, total=6
Expected Output / Criteria
0.5