# import random library and set seed
import random
random.seed(10001)
# 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
#
#def the function name, draw a number 1-100 and test our condition
def draw_ball():
random_ball=random.randint(1,100)
if random_ball >= 52:
return True
else:
return False
print(draw_ball())
# Step 2.
# Create a function which simulates playing the game n_plays times; keep track of number of wins and losses
#
#define our function which takes three parameters the number of simulations, the bankroll, and the bet size
def draw_ball_n_times(n,bankroll,bet):
player_wins = 0
player_losses = 0
for i in range(0,n):
if(draw_ball()==True):
bankroll += bet
player_wins += 1
else:
bankroll -= bet
player_losses += 1
return (bankroll,player_wins,player_losses)
#Test our function for 5 games with 10000 bankroll with 100 size bets
print("Number of Games Simulated, Wins, Losses")
draw_ball_n_times(5,10000,100)
#Initialize our wins, losses, funds amout and a list for results
wins=0
losses=0
funds=0
simulation_results=[0,0,0]
for i in range(100):
simulation_results=draw_ball_n_times(5,10000,100)
funds+=simulation_results[0]
wins+=simulation_results[1]
losses+=simulation_results[2]
#calculate average funds and print it
average_funds = funds/100
print(f'The average funds is {average_funds}')
discrete_win_prob= wins/500
discrete_loss_prob= 1- discrete_win_prob
print(f'The discrete probability of winning is {discrete_win_prob} and the discrete probability of losing is {discrete_loss_prob}')
expected_value = (100*discrete_win_prob) - (100*discrete_loss_prob)
print(f'The expected value is {expected_value}')
# 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
#