import numpy as np
m = 10000
a = 0
b = 0
y1 = np.random.normal(loc=14,scale=2,size=m)
y2 = np.random.normal(loc=23,scale=3,size=m)
y3 = np.random.normal(loc=22,scale=4,size=m)
y =y1 + y2 + y3
a,b = np.mean(y),np.var(y)
print(a,b )
# (59.08396232409535, 29.120136564111085)
# 理論均值為59 = 14 + 23 + 22 方差為29 = 2*2 + 3*3 + 4*4
import math
import random
def play(change):
prize = random.randint(0, 2)
guess = random.randint(0, 2)
if guess == prize:
if change:
return False
else:
return True
else:
if change:
return True
else:
return False
def winRate(change, N):
win = 0
for i in range(N):
if play(change):
win += 1
print("中獎率為{}".format(win / N))
N = 1000000
print("每次換門的中獎概率:")
winRate(True, N)
print("每次都不換門的中獎概率:")
winRate(False, N)
# 理論換門2/3 不換門1/3
# 每次換門的中獎概率:
# 中獎率為0.665769
# 每次都不換門的中獎概率:
# 中獎率為0.33292
import time
import random
for i in range(10):
print(time.strftime("%Y-%m-%d %X", time.localtime()))
dou = {1994: {'褐色': 30, '黃色': 20, '紅色': 20, '綠色': 10, '橙色': 10, '黃褐': 30},
1996: {'藍色': 24, '綠色': 20, '橙色': 16, '黃色': 14, '紅色': 13, '褐色': 13}}
num = 10000
list_1994 = ['褐色'] * 30 * num + ['黃色'] * 20 * num + ['紅色'] * 20 * num + ['綠色'] * 10 * num + ['橙色'] * 10 * num + ['黃褐'] * 10 * num
list_1996 = ['藍色'] * 24 * num + ['綠色'] * 20 * num + ['橙色'] * 16 * num + ['黃色'] * 14 * num + ['紅色'] * 13 * num + ['褐色'] * 13 * num
random.shuffle(list_1994)
random.shuffle(list_1996)
count_all = 0
count_key = 0
for key in range(100 * num):
if list_1994[key] == '黃色' and list_1996[key] == '綠色':
count_all += 1
count_key += 1
if list_1994[key] == '綠色' and list_1996[key] == '黃色':
count_all += 1
print(count_key / count_all, 20 / 27)
print(time.strftime("%Y-%m-%d %X", time.localtime()))
# ...
# 0.7407064573459715 0.7407407407407407
# 20/27是理論答案
0條評論