Python Puzzles
Your favorite football team has the following pre-season estimated win percentages for their 12-game schedule. What is the most likely outcome for their final win total?
The win percentages are 95%, 26%, 55%, 63%, 45%, 75%, 60%, 52%, 51%, 72%, 59% and 81%.
The most likely outcome is 7 wins. Surprisingly, there are 2 simulations with 0 wins, even though the team is favored in 10 of the 12 games.
Most likely outcome for final win total: 7
Number of wins: 0, Count: 2
Number of wins: 1, Count: 5
Number of wins: 2, Count: 88
Number of wins: 3, Count: 638
Number of wins: 4, Count: 2931
Number of wins: 5, Count: 8394
Number of wins: 6, Count: 17234
Number of wins: 7, Count: 23958
Number of wins: 8, Count: 23278
Number of wins: 9, Count: 15384
Number of wins: 10, Count: 6439
Number of wins: 11, Count: 1486
Number of wins: 12, Count: 163import numpy as np
# Define win probabilities
win_probabilities = [0.95, 0.26, 0.55, 0.63, 0.45, 0.75, 0.60, 0.52, 0.51, 0.72, 0.59, 0.81]
# Define number of simulations
num_simulations = 100000
# Define a function to simulate a season
def simulate_season():
wins = 0
for prob in win_probabilities:
result = np.random.choice([1, 0], p=[prob, 1 - prob]) # Simulate a game with given win probability
wins += result
return wins
# Run simulations
win_totals = [simulate_season() for _ in range(num_simulations)]
# Analyze results
(unique, counts) = np.unique(win_totals, return_counts=True)
most_likely_wins = unique[np.argmax(counts)]
print(f"Most likely outcome for final win total: {most_likely_wins}")
# Print count of each number of wins
for (win_total, count) in zip(unique, counts):
print(f"Number of wins: {win_total}, Count: {count}")
