You are on page 1of 4

#Import required libraries :

import random
import matplotlib.pyplot as plt

"""RULES :
1) There are chits containing numbers ranging from 1-100 in a bag.
2) Users can bet on even or odd.
3) In this game 10 and 11 are special numbers. 10 will be counted as an odd number
and 11 will be counted as an even number.
4) If you bet on even number and if you get 10 then you lose.
5) If you bet on odd number and if you get 11 then you lose.
"""

#Place your bet:

#User can choose even or odd number :


choice = input("Do you want to bet on Even number or odd number \n")

#For even :
if choice=="Even":
def pickNote():
#Get random number between 1-100.
note = random.randint(1,100)

#Check for our game conditions.

#Notice that 10 isn't considered as even number.


if note%2!=0 or note==10:
return False
elif note%2==0:
return True

#For odd :
elif choice=="Odd":
def pickNote():
#Get random number between 1-100.
note = random.randint(1,100)

#Check for our game conditions.

#Notice that 11 isn't considered as odd number.


if note%2==0 or note==11:
return False
elif note%2==1:
return True

#Main function :
def play(total_money, bet_money, total_plays):

num_of_plays = []
money = []

#Start with play number 1


play = 1

for play in range(total_plays):


#Win :
if pickNote():
#Add the money to our funds
total_money = total_money + bet_money
#Append the play number
num_of_plays.append(play)
#Append the new fund amount
money.append(total_money)

#Lose :
else:
#Add the money to our funds
total_money = total_money - bet_money
#Append the play number
num_of_plays.append(play)
#Append the new fund amount
money.append(total_money)

#Plot the data :


plt.ylabel('Player Money in $')
plt.xlabel('Number of bets')
plt.plot(num_of_plays,money)

#Final value after all the iterations :


final_funds.append(money[-1])
return(final_funds)

#Create a list for calculating final funds


final_funds= []

#Run 10 iterations :
for i in range(10):
ending_fund = play(10000,100,50)

print(ending_fund)
print(sum(ending_fund))

#Print the money the player ends with


print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

#Create a list for calculating final funds


final_funds= []

#Run 1000 iterations :


for i in range(1000):
ending_fund = play(10000,100,50)

#Print the money the player ends with


print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

#Create a list for calculating final funds


final_funds= []

#Run 10 iterations :
for i in range(10):
ending_fund = play(10000,100,5)

#Print the money the player ends with


print("Number of bets = 5")
print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

#Create a list for calculating final funds


final_funds= []

#Run 10 iterations :
for i in range(10):
ending_fund = play(10000,100,10)

#Print the money the player ends with


print("Number of bets = 10")
print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

#Create a list for calculating final funds


final_funds= []

#Run 10 iterations :
for i in range(10):
ending_fund = play(10000,100,100)

#Print the money the player ends with


print("Number of bets = 100")
print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

#Create a list for calculating final funds


final_funds= []

#Run 10 iterations :
for i in range(10):
ending_fund = play(10000,100,1000)

#Print the money the player ends with


print("Number of bets = 1000")
print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

#Create a list for calculating final funds


final_funds= []

#Run 10 iterations :
for i in range(10):
ending_fund = play(10000,100,5000)

#Print the money the player ends with


print("Number of bets = 5000")
print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

#Create a list for calculating final funds


final_funds= []
#Run 10 iterations :
for i in range(10):
ending_fund = play(10000,100,10000)

#Print the money the player ends with


print("Number of bets = 10000")
print("The player started with $10,000")
print("The player left with $",str(sum(ending_fund)/len(ending_fund)))

You might also like