标签:else car rand ice log 输出 分析 style col
1 import random 2 win=0; 3 lose=0; 4 for i in range(1000): 5 car=random.randint(1,3); 6 choice=random.randint(1,3); 7 if car==choice: 8 lose=lose+1; 9 else: 10 win=win+1; 11 print("模拟1000次,换得到汽车的概率为:",win/1000); 12 print("模拟1000次,不换得到汽车的概率为:",lose/1000);
一、概率没有发生变化;
二、应当选择换。第一次选中羊的概率为2/3,换则得到汽车;第一次选中汽车的概率为1/3,换则得到羊;故换得到汽车的概率为2/3。
三、程序验证支持分析结果,输出约为换得到汽车的概率为0.66,不换得到汽车的概率为0.34;
四、代码见上图。
标签:else car rand ice log 输出 分析 style col
原文地址:http://www.cnblogs.com/hysssblog/p/7683801.html