Addition Rules & Counting Principles
Mutually exclusive events, general addition theorems, multi-category frequency tables, permutations, and combinatorial probability with Python 3.
Lab 01 Tasks: Model Review
Complement Defect Model: Defect rate p = 0.08, n = 4. Probability of at least one defect.
Badge Key Permutations: 2 uppercase letters + 5 digits without repetition. P(Crack) = 4.89e-8.
Dependent 3-Card Draw: King then Queen then Jack without replacement.
p_defect = 0.08
p_at_least_one = 1 - (1 - p_defect) ** 4
print("Task 1:", round(p_at_least_one, 5))
# Task 2: Security Badge Permutations
keys = (26 ** 2) * (10 * 9 * 8 * 7 * 6)
p_crack = 1 / keys
print(f"Task 2 Keys: {keys} | P: {p_crack:.2e}")
# Task 3: 3-Card Dependent Draw
p_cards = (4 / 52) * (4 / 51) * (4 / 50)
print("Task 3:", round(p_cards, 6))
Task 1: 0.28361
Task 2 Keys: 20442240 | P: 4.89e-08
Task 3: 0.000483
Mutually Exclusive Events
Fours and Aces: 4 fours and 4 aces in standard 52-card deck
Direct Sum: Add mutually exclusive probabilities without overlap
p_four = 4 / 52
p_ace = 4 / 52
probability = p_four + p_ace
print("P(4 or Ace):", round(probability, 5))
P(4 or Ace): 0.15385
General Addition Rule
Identify Overlap: Event A below 3 and Event B odd share outcome 1
Apply Theorem: (2/6) + (3/6) - (1/6) = 4/6 ≈ 0.6667
p_a = 2 / 6
p_b = 3 / 6
p_overlap = 1 / 6
probability = p_a + p_b - p_overlap
print("P(A or B):", round(probability, 4))
P(A or B): 0.6667
Blood-Type Addition Counts
Substitute Counts: Type B (45) + Rh-Neg (65) - Overlap (8) = 102
Calculate Ratio: Divide favorable category sum by sample size (409)
favorable = 45 + 65 - 8
total = 409
probability = favorable / total
print("P(B or Rh-):", round(probability, 4))
P(B or Rh-): 0.2494
Factorials & Permutations
Sudoku Row: 9 distinct digits in 9 positions: 9×8×7×6×5×4×3×2×1
Code without repeats: 10 choices × 9 choices × 8 choices
# Sudoku 9-digit arrangement
sudoku = math.factorial(9)
# 3-digit code from 10 digits without repeats
codes = 10 * 9 * 8
print("Sudoku:", sudoku)
print("Codes:", codes)
Sudoku: 362880 Codes: 720
Combinations Formula
Choose 4 Companies from 16: (16×15×14×13)/(4×3×2×1) = 1,820
# Choose 4 from 16 companies
groups = math.comb(16, 4)
print("4-Company Selections:", groups)
# Multinomial house arrangements
houses = math.factorial(12) // (
math.factorial(6) * math.factorial(4) * math.factorial(2)
)
print("House Arrangements:", houses)
4-Company Selections: 1820 House Arrangements: 13860
Combination Probability
Affected & Unaffected: C(3,1) × C(397,3)
All Selections: C(400,4) = 1,050,739,900; Ratio = 0.02955
favorable = math.comb(3, 1) * math.comb(397, 3)
total = math.comb(400, 4)
probability = favorable / total
print("Probability:", round(probability, 5))
Probability: 0.02955