Probability Calculator
Calculate single event, compound (AND/OR), conditional, and at-least-one probabilities.
About this tool
Understanding probability is essential for making informed decisions in fields ranging from science and statistics to gaming and finance. This Probability Calculator helps you compute probabilities for various scenarios—whether you're assessing the likelihood of a single event, analyzing compound events that must satisfy multiple conditions, or determining conditional probabilities that depend on prior outcomes. By automating these calculations, the tool eliminates manual arithmetic errors and makes probability theory accessible to students, researchers, and professionals alike.
Using the calculator is straightforward: select the type of probability you want to compute (single event, AND/OR compound events, conditional, or at-least-one scenarios), enter the relevant values (individual probabilities or outcomes), and the tool instantly displays the result as both a decimal and a percentage. Common use cases include predicting dice roll outcomes, calculating the chance of drawing specific cards from a deck, assessing equipment failure rates, evaluating medical test accuracy, or analyzing game strategies where multiple independent or dependent events interact.
For accurate results, ensure your input probabilities are between 0 and 1, and remember that 'AND' means all events must occur (multiplication rule) while 'OR' means at least one event occurs (addition rule adjusted for overlaps). Conditional probability calculations are particularly useful in real-world scenarios like Bayesian reasoning in medical diagnostics or quality control testing, where the probability of an outcome depends critically on what happened before.
Frequently Asked Questions
Code Implementation
from fractions import Fraction
import math
def single_event_probability(favorable: int, total: int) -> dict:
"""P(A) = favorable / total"""
if total <= 0:
raise ValueError("Total outcomes must be positive")
prob = favorable / total
frac = Fraction(favorable, total)
return {
"decimal": round(prob, 6),
"fraction": f"{frac.numerator}/{frac.denominator}",
"percentage": round(prob * 100, 4),
}
def compound_and_probability(p_a: float, p_b: float) -> float:
"""P(A and B) = P(A) × P(B) for independent events"""
return p_a * p_b
def compound_or_probability(p_a: float, p_b: float) -> float:
"""P(A or B) = P(A) + P(B) - P(A and B) for independent events"""
return p_a + p_b - p_a * p_b
def at_least_one_probability(p_single: float, trials: int) -> float:
"""P(at least one) = 1 - P(none) = 1 - (1-p)^n"""
return 1 - (1 - p_single) ** trials
# Examples
print("=== Single Event ===")
r = single_event_probability(3, 6) # Rolling a 1, 2, or 3
print(f"P = {r['fraction']} = {r['decimal']} = {r['percentage']}%")
print("\n=== Compound (AND) ===")
p_and = compound_and_probability(1/6, 1/6) # Two dice both show 1
print(f"P(1 and 1) = {p_and:.6f} = {p_and*100:.4f}%")
print("\n=== Compound (OR) ===")
p_or = compound_or_probability(0.5, 0.3)
print(f"P(A or B) = {p_or:.6f} = {p_or*100:.2f}%")
print("\n=== At Least One ===")
p_atleast = at_least_one_probability(1/6, 3) # At least one 6 in 3 rolls
print(f"P(at least one 6 in 3 rolls) = {p_atleast:.6f} = {p_atleast*100:.2f}%")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.