之前一直在准备比赛的事,今天把代码贴上来。
import time import random change_time = 0 no_change_time = 0 car = 0 select = 0 try: f = eval(input("输入羊车门问题测试次数:")) start = time.clock() for i in range(1,f+1): car = random.randint(1,3) select = random.randint(1,3) if car==select: no_change_time = no_change_time+1 else: change_time = change_time+1 print("不改变得车概率{}".format(no_change_time/f)) print("改变后得车概率{}".format(change_time/f)) end = time.clock() print("运行时间: %f s" % (end - start)) except: print("发生错误!请输入一个整数!")