推理过程如图所示:
代码如下图所示:
import math
import random
def game(change):
prize=random.randint(0,2)
guess=random.randint(0,2)
if guess != prize:#若一开始选中羊
if change:#此时转换一定得奖
return True
else:
return False
else:#若一开始选车
if change:#此时转换一定不会得奖
return False
else:
return True
def winRate(change,N):#N是玩的次数
win=0
for i in range(N):
if(game(change)):
win+=1
print(win/N)
N=1000000
print("The winning rate of each door change:")
winRate(True,N)
plt.plot(win/N)
代码运行结果如图所示: