# import random library and set seed
import random
random.seed(123456)
# Step 1.
# Define a function which randomly draws a ball with an integer between 1 and 100 on it;
# then returns True if Player
# wins and returns False if House wins.
# Add a print statement to function to print random integer and test out function
# Add comment statements to function
#
Ball = 0
def ballGame():
Ball = random.randint(1,100)
print (f'{Ball}')
if (Ball >= 52):
print ('Win')
return True
else:
print ('Loss')
return False
print (ballGame())
# Step 2.
# Create a function which simulates playing the game n_plays times; keep track of number of wins and losses
#
def gameSim(plays, money, bet):
wins = 0
losses = 0
for i in range(0,plays):
if (ballGame()==True):
money+=bet
wins+=1
else:
money-=bet
losses+=1
return [money,wins,losses]
print (gameSim(5,10000,100))
totalWins = 0
totalLosses = 0
totalMoney = 0
Results = [0,0,0]
for i in range(100):
Results = gameSim(5,10000,100)
totalMoney += Results[0]
totalWins += Results[1]
totalLosses += Results[2]
avgMoney = totalMoney/100
print (f'{avgMoney} is the average amount of funds left after playing 5 games.')
discreteWin = totalWins/500
discreteLoss = 1-discreteWin
print (f'The discrete probability of winning is: {discreteWin}, losing is: {discreteLoss}')
#More games are required for the sample
games = 5
rounds = 1000000
totalGames = games*rounds
Results = gameSim(totalGames,10000,100)
totalMoney = Results[0]
totalWins = Results[1]
totalLosses = Results[2]
discreteWin = totalWins/totalGames
discreteLoss = 1-discreteWin
avgMoney = totalMoney/totalGames
print (f'{avgMoney} is the average amount of funds left after playing {totalGames} games.')
print (f'The discrete probability of winning is: {discreteWin}, losing is: {discreteLoss}')
# 1. import random and set seed
# 2. Input target sales and number of sales persons for upcoming year; low and high
# percentages of sales for generating random numbers
# 3. Generate a random sales amount for each rep and check that it is in the correct range
# Use a for loop; round answer to nearest cent
# 4. Add to your loop in # 3 to determine the commission for each rep
# (you need an if-elif-else construct to determine rate); keep a running tab of
# the sum of all commissions
# round all dollar amounts to nearest cent
#
# 5. Add a loop around your code in # 4 to do 10,000 simulations
# Only print out the average commission for all 10,000 simulations
# Don't print out all the information from Step # 4 - it will be way too much so remove
# or comment out those print statements
#