import random
import matplotlib.pyplot as plt
bowl = ["bowl_1", "bowl_1", "bowl_2", "bowl_3", "bowl_3", "bowl_3"]
bowl_1 = ['r','r','w','w','w','w']
bowl_2 = ['r','w','w']
bowl_3 = ['r','r','r','r','r','w','w','w','w']
red_counter = 0
bowl1_red = 0
bowl2_red = 0
bowl3_red = 0
rel_freq_red = []
rel_freq_1 = []
rel_freq_2 = []
rel_freq_3 = []
for i in range(100000):
random_int = random.randint(0,len(bowl)-1)
if bowl[random_int] == "bowl_1":
random_int_2 = random.randint(0,len(bowl_1)-1)
if bowl_1[random_int_2] == 'r':
red_counter+=1
bowl1_red+=1
elif bowl[random_int] == "bowl_2":
random_int_2 = random.randint(0,len(bowl_2)-1)
if bowl_2[random_int_2] == 'r':
red_counter+=1
bowl2_red+=1
else:
random_int_2 = random.randint(0,len(bowl_3)-1)
if bowl_3[random_int_2] == 'r':
red_counter+=1
bowl3_red+=1
rel_freq_red.append(red_counter/(i+1))
if red_counter !=0:
rel_freq_1.append(bowl1_red/red_counter)
rel_freq_2.append(bowl2_red/red_counter)
rel_freq_3.append(bowl3_red/red_counter)
plt.figure(figsize=(8,6), dpi=80)
plt.plot([x for x in range(len(rel_freq_red))], rel_freq_red, label="Relative Frequency of R")
plt.plot([x for x in range(len(rel_freq_1))], rel_freq_1, label="Relative Frequency of B1|R")
plt.plot([x for x in range(len(rel_freq_2))], rel_freq_2, label="Relative Frequency of B2|R")
plt.plot([x for x in range(len(rel_freq_3))], rel_freq_3, label="Relative Frequency of B3|R")
plt.axhline(y=4/9, linestyle=':', color='blue', label="Probability of R")
plt.axhline(y=1/4, linestyle=':', color='orange', label="Probability of B1|R")
plt.axhline(y=1/8, linestyle=':', color="green", label="Probability of B2|R")
plt.axhline(y=5/8, linestyle=':', color='red', label="Probability of B3|R")