因此,我想编写一个蒙特卡洛模拟程序,以进行三次选秀。每次拾取卡片时,都会将其放回卡组中。这三个选择的模拟将运行100次,我想计算每个选择都选择一张面孔牌(国王,皇后,杰克)的概率。除了列表卡,还有其他更简单的方法吗?这是我的代码:
#Letters `Q`, `K` and `J` represent king, queen and jack
def pickCard():
return np.random.choice([1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,'J','J','J','J'
,'K','K','K','K', 'Q','Q','Q','Q'])
def checkPick(numTrials):
numWins=0
x=[]
for i in range(numTrials):
for j in range(3):
d1 = pickCard()
d2 = pickCard()
d3 = pickCard()
if (d1=='Q' or d1=='K' or d1=='J') and (d2 =='Q' or d2=='K' or d2=='J') and (d3 == 'Q' or d3=='K' or d3=='J'):
numWins+=1
break
print('Probability of picking a face card =', numWins/numTrials)
checkPick(100)