# 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
#
def drawball (n_plays) :
ball = random.randint (1, 100)
if (ball >=52):
return True
else :
return False
print (f' the number drawn is {ball}' )
drawball (1)

```
the number drawn is 38
```

# Step 2.
# Create a function which simulates playing the game n_plays times; keep track of number of wins and losses
def gameplay (n_plays, funds, bet) :
wins = 0
losses = 0
for i in range (0, n_plays) :
if (drawball (n_plays) == True) :
funds = funds +bet
wins = wins + 1
else :
funds = funds - bet
losses = losses +1
return [funds, wins, losses]
drawball (3)

#step 2 with a fake true and false
#i tried printing out and tallying up wins to losses but it wasnt working with what i did above
#i dont use this code for the remainder of the project but these are my thoughts on how to do that
def draw (n_plays) :
outcomes= ['true', 'false']
n_true = 0 ; n_false = 0
for i in range (0, n_plays) :
ball = random.randint (1, 100)
if (ball >= 52) :
n_true = n_true +1
print ('true')
else :
n_false = n_false +1
print ('false')
return ( [n_true, n_false])
draw (8)

```
true
false
true
false
true
false
false
false
```

print (gameplay (5, 10000, 100))

```
[9500, 0, 5]
```

#simulation of 5 games x 100
total_funds = 0
total_wins = 0
total_losses = 0
results = [0, 0, 0]
for i in range (1, 100) :
results = gameplay(5, 10000, 100)
total_funds = total_funds + results[0]
total_wins = total_wins + results[1]
total_losses = total_losses + results[2]
averagefunds= total_funds / 100
print (f' the average number of funds after playing 5 games is {averagefunds}')
#discrete probability calculations
discprobwin= total_wins/500
discproblose= 1- discprobwin
#complement rule applied
discexpected= ((100*discprobwin) - (100*discproblose))
print (f' the discrete probability of winning is {discprobwin} and the discrete probability of losing is {discproblose}')
print (f' the discrete expected value is {discexpected}')

```
the average number of funds after playing 5 games is 9863.0
the discrete probability of winning is 0.458 and the discrete probability of losing is 0.542
the discrete expected value is -8.399999999999999
```

#modification for losing about 2 dollars per game
# in order to get a better approximation more games need to played according to the law of increasing numbers
#number picked for amount of games is arbitrary; thats the biggest number i could input without the code taking too long to run
results = gameplay(500000, 10000, 100)
total_funds = results[0]
total_wins = results[1]
total_losses = results[2]
discprobwin= total_wins/500000
discproblose= 1- discprobwin
discexpected= ((100*discprobwin) - (100*discproblose))
print (f' the discrete probability of winning is {discprobwin} and the discrete probability of losing is {discproblose}')
print (f' the discrete expected value is {discexpected}')
#theoretical expected value is now closer to losing about 2 dollars per game whereas it was more than 8 dollars in the above section

```
the discrete probability of winning is 0.490216 and the discrete probability of losing is 0.509784
the discrete expected value is -1.9568000000000012
```

# 1. import random and set seed
import random
random.seed (123456)

# 2. Input target sales and number of sales persons for upcoming year; low and high
# percentages of sales for generating random numbers
print ('***************************************')
print ('sales rep 1')
commission = actual sales * commission rate
sales_low = 112500 ; sales_ high = 165000
sales1= random.randint (sales_low, sales_high)
print ('the number of sales is', sales1)

SyntaxError: invalid syntax (<ipython-input-44-e394ad4cf714>, line 6)

# 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
#