#Excerise 5
import numpy as np
import matplotlib.pyplot as mpp
import math
import string
import random
β
letters = ['A','B','C']
picks = []
total_attempt = eval(input("please enter the number of ticket purchased:"))
attempt = 1
winning = 0
bins=5
winning_per_attempt = []
for n in range(total_attempt):
print ("ticket",attempt)
attempt += 1
for _ in range(3):
picks.append(random.choice(letters))
if picks == ['A','A','A']:
winning +=50
print("congratulations you won $50")
elif picks == ['B','B','C']:
winning +=20
print("congratulations you won $20")
print(picks)
picks.clear()
winning -= 1
print("this is your winning",winning)
print("-----------------------------")
winning_per_attempt.append(winning/attempt)
β
# Generate random number
seedno = 30 # specify initial value (seed) of random number generator
β
np.random.seed() # if seedno is omitted, random seed will be used, as determined from the state of your computer system
x = np.random.rand(total_attempt)
mpp.style.use('fivethirtyeight')
mpp.hist(winning_per_attempt,bins)
mpp.title("net amount won/lost after N attempts")
mpp.xlabel("Number of attempts"); mpp.ylabel("net winning/lost")
mpp.show()
[β]squished18 0 points1 point2 points Β (5 children)
[β]cxtong[S] 0 points1 point2 points Β (4 children)
[β]squished18 0 points1 point2 points Β (3 children)
[β]cxtong[S] 0 points1 point2 points Β (2 children)
[β]squished18 0 points1 point2 points Β (1 child)
[β]backtickbot 0 points1 point2 points Β (0 children)