You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are the payoff values for the lottery gamepayoff = {'jp': 5000000, 'fivec': 350000, 'five': 1500, 'four': 100, 'three': 10, 'twoc': 5, 'two': 3}actual_payoff = {'jp': 5000000-3, 'fivec': 350000-3, 'five': 1500-3, 'four': 100-3, 'three': 10-3, 'twoc': 5-3, 'two': 3-3}
[ ]
This dictionary will contain the results of the lottery gamesresults = {'jp': 0,'fivec': 0,'five': 0,'four': 0, 'three': 0, 'twoc': 0, 'two': 0}
[ ]
def play_games(ng): for i in range(ng): # The lottery selection corp = rng_corp.choice(range(1,50), 7, replace=False) corp_six = set(corp[0:6]) corp_all = set(corp) # The player selection player = rng_player.choice(range(1,50), 6, replace=False) player = set(player) match = len(corp_six.intersection(player)) matchc = len(corp_all.intersection(player)) #print(match) if match == 6: results['jp'] += 1 elif match == 5: if matchc == 6: results['fivec'] += 1 else: results['five'] += 1 elif match == 4: results['four'] += 1 elif match == 3: results['three'] += 1 elif match == 2: if matchc == 3: results['twoc'] += 1 else: results['two'] += 1
[ ]
num_games = 1000000
play_games(num_games)
[ ]
total_winning_probabilities = {}
for prize in results:
if prize != 'none':
winning_probability = results[prize] / num_games
total_winning_probabilities[prize] = winning_probability
[ ]
losing_probability = 1 - sum(total_winning_probabilities.values())
[ ]
print("Probability of Winning:")
for prize, probability in total_winning_probabilities.items():
print(f"{prize}: {probability:.4f}")
print(f"Probability of Losing: {losing_probability:.4f}")
output
Probability of Winning:
jp: 0.0000
fivec: 0.0000
five: 0.0000
four: 0.0010
three: 0.0176
twoc: 0.0121
two: 0.1201
Probability of Losing: 0.8492
[ ]
from numpy.random import sample
[ ]
sample_average = sum(result * payoff[prize] for prize, result in results.items()) / num_games
sample_std_dev = np.sqrt(sum(((payoff[prize] - sample_average) ** 2) * result for prize, result in results.items()) / num_games)
[ ]
theoretical_expected_value = sum(result * payoff[prize] for prize, result in results.items()) / num_games
[ ]
print("Sample Average Value:", sample_average)
print("Sample Standard Deviation:", sample_std_dev)
print("Theoretical Expected Value:", theoretical_expected_value)
output
Sample Average Value: 0.730444
Sample Standard Deviation: 7.988019761051721
Theoretical Expected Value: 0.730444
[ ]
plt.bar(results.keys(), results.values())
plt.xlabel('prize')
plt.ylabel('frequency')
plt.title('lottery game results')
plt.show()
print(results)
output
Adapt the notebook to also count and plot five matches, five matches and compliment and jackpots.
Dress up the visualisation with a title and title axes.
There are eight possible oucomes in this game. The eighth one, when none of the matches described above happens, and the player does not get any prise. The cost of a tcket is 3 dollars.
Compute the sample average value for this game and the sample standard deviation.
Compare the sample average value with the theoretical expected value for this game
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
import numpy as npimport matplotlib.pyplot as plt
[ ]
rng_corp = np.random.default_rng(711)rng_player = np.random.default_rng(348)
[ ]
These are the payoff values for the lottery gamepayoff = {'jp': 5000000, 'fivec': 350000, 'five': 1500, 'four': 100, 'three': 10, 'twoc': 5, 'two': 3}actual_payoff = {'jp': 5000000-3, 'fivec': 350000-3, 'five': 1500-3, 'four': 100-3, 'three': 10-3, 'twoc': 5-3, 'two': 3-3}
[ ]
This dictionary will contain the results of the lottery gamesresults = {'jp': 0,'fivec': 0,'five': 0,'four': 0, 'three': 0, 'twoc': 0, 'two': 0}
[ ]
def play_games(ng): for i in range(ng): # The lottery selection corp = rng_corp.choice(range(1,50), 7, replace=False) corp_six = set(corp[0:6]) corp_all = set(corp) # The player selection player = rng_player.choice(range(1,50), 6, replace=False) player = set(player) match = len(corp_six.intersection(player)) matchc = len(corp_all.intersection(player)) #print(match) if match == 6: results['jp'] += 1 elif match == 5: if matchc == 6: results['fivec'] += 1 else: results['five'] += 1 elif match == 4: results['four'] += 1 elif match == 3: results['three'] += 1 elif match == 2: if matchc == 3: results['twoc'] += 1 else: results['two'] += 1
[ ]
num_games = 1000000
play_games(num_games)
[ ]
total_winning_probabilities = {}
for prize in results:
if prize != 'none':
winning_probability = results[prize] / num_games
total_winning_probabilities[prize] = winning_probability
[ ]
losing_probability = 1 - sum(total_winning_probabilities.values())
[ ]
print("Probability of Winning:")
for prize, probability in total_winning_probabilities.items():
print(f"{prize}: {probability:.4f}")
print(f"Probability of Losing: {losing_probability:.4f}")
output
Probability of Winning:
jp: 0.0000
fivec: 0.0000
five: 0.0000
four: 0.0010
three: 0.0176
twoc: 0.0121
two: 0.1201
Probability of Losing: 0.8492
[ ]
from numpy.random import sample
[ ]
sample_average = sum(result * payoff[prize] for prize, result in results.items()) / num_games
sample_std_dev = np.sqrt(sum(((payoff[prize] - sample_average) ** 2) * result for prize, result in results.items()) / num_games)
[ ]
theoretical_expected_value = sum(result * payoff[prize] for prize, result in results.items()) / num_games
[ ]
print("Sample Average Value:", sample_average)
print("Sample Standard Deviation:", sample_std_dev)
print("Theoretical Expected Value:", theoretical_expected_value)
output
Sample Average Value: 0.730444
Sample Standard Deviation: 7.988019761051721
Theoretical Expected Value: 0.730444
[ ]
plt.bar(results.keys(), results.values())
plt.xlabel('prize')
plt.ylabel('frequency')
plt.title('lottery game results')
plt.show()
print(results)
output
Adapt the notebook to also count and plot five matches, five matches and compliment and jackpots.
Dress up the visualisation with a title and title axes.
There are eight possible oucomes in this game. The eighth one, when none of the matches described above happens, and the player does not get any prise. The cost of a tcket is 3 dollars.
Compute the sample average value for this game and the sample standard deviation.
Compare the sample average value with the theoretical expected value for this game
Beta Was this translation helpful? Give feedback.
All reactions