Compute nCr(5,2), nPr(5,2), and the European-roulette expectation 35·(1/37) + (−1)·(36/37). Print all three.
Compute nCr(5,2), nPr(5,2), and the European-roulette expectation 35·(1/37) + (−1)·(36/37). Print all three.
Answer
from math import factorial def nPr(n, r): return factorial(n) // factorial(n - r) def nCr(n, r): return factorial(n) // (factorial(n - r) * factorial(r)) # Roulette: win 35 with p = 1/37, lose 1 with p = 36/37 e_roulette = 35 * (1 / 37) + (-1) * (36 / 37) print(f"nCr(5,2)={nCr(5, 2)}") print(f"nPr(5,2)={nPr(5, 2)}") print(f"E[roulette] = {e_roulette:.3f}")