【发布时间】:2020-11-01 08:53:40
【问题描述】:
我正在编写一个程序,以在 Monty Hall 问题中找到 4 个门的概率,但没有打印出更改选择的概率。
import random
door = ['a', 'b', 'c', 'd']
nc = 0 # When not changed
c = 0 # When changed
tr = 100 #Total number of iterations
for a in range(tr):
car = random.randint(0, 3) #Inquiry number with car behind
pc = random.randint(0, 3) #Inquiry number chosen by the participant
ed = [] #Empty door
for i in range(4):
if i != pc and i != car:
ed.append(door[i])
com = random.sample(ed, 2)
if pc == car:
nc += 1
def list_remover(the_list, val):
while val in the_list:
the_list.remove(val)
list_remover(ed, com)
if not ed:
c += 1
print((nc / tr) * 100, "%")
print((c / tr) * 100, "%")
【问题讨论】:
-
打印出来等于
0%。预期的结果是什么?