Skip to content

fix(statistics): add probability() function#115

Merged
antfullstack merged 1 commit intoantfullstack:mainfrom
tysoncung:fix/105-add-probability
Apr 12, 2026
Merged

fix(statistics): add probability() function#115
antfullstack merged 1 commit intoantfullstack:mainfrom
tysoncung:fix/105-add-probability

Conversation

@tysoncung
Copy link
Copy Markdown
Contributor

Problem

Issue #105 requested a probability() function in statistics.py that computes favorable_outcomes / possible_outcomes and returns a float approximation — e.g. the probability of rolling a 4 on a die is probability(1, 6)0.1666...

Solution

Added probability(favorable_outcomes, possible_outcomes) with:

  • Straightforward ratio calculation returning a float
  • ValueError guard when possible_outcomes == 0
  • ValueError guard when either argument is negative
  • Full docstring following the project convention

Files Changed

  • simple_equ/economics/statistics.py — added probability() function

Verification

from simple_equ.economics.statistics import probability

probability(1, 6)  # ≈ 0.1667 — rolling a specific side on a die
probability(3, 6)  # 0.5 — rolling an even number
probability(0, 6)  # 0.0
probability(6, 6)  # 1.0

Closes #105

Implement probability(favorable_outcomes, possible_outcomes) in statistics.py.

Returns favorable_outcomes / possible_outcomes as a float — e.g.
probability(1, 6) ≈ 0.1667 (rolling a specific value on a dice).

Guards:
- Raises ValueError when possible_outcomes == 0
- Raises ValueError when either argument is negative
@antfullstack
Copy link
Copy Markdown
Owner

Thank you very mush for your contribution! I really appreciate the error handling considerations and structure.

@antfullstack antfullstack merged commit 82459a2 into antfullstack:main Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add propability function in statistics

2 participants