上面是依据条件概率的相关理解编写的程序,下面是根据过程编写的程序;
import random n=eval(input ("请输入模拟次数:")) n1=0 #猜中汽车的次数 b=eval (input ("请输入猜测的号码:")) cho=input("请输入是否更改选择:(y or n)") for i in range(n): a1=(random.random())*3//1+1 #汽车所在的门的序号 while True: a2=(random.random())*3//1+1 #给出一个门后是羊的提示 if a2==a1: continue elif a2==b: continue else: break if cho=="y": #更改自己的选择 while True: b1=(random.random())*3//1+1 if b1==b or b1==a2: continue else: break b=b1 if b==a1: n1+=1 c=n1/n if cho=="y" : print ("更改选择后的概率为:{}".format(c)) else: print ("改变选择后的概率为:{}".format(c))转载于:https://www.cnblogs.com/breakcozy/p/6636164.html
相关资源:各显卡算力对照表!