清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#coding: utf-8 import random num_loss = 0 num_win = 0 num = 0 while True: door = [1,2,3] luck_door = random.randint(1,3) while True: try: choose_door = int(raw_input(u'请输入你选择的门号(1,2,3):')) if choose_door>0 and choose_door <=3: break except: print u'输入错误' if choose_door == luck_door: door.remove(choose_door) remove_door = random.choice(door) while True: sel = int(raw_input(str(remove_door)+ u'是错误的门,是否换至另一个门(1:是;2:否):')) if sel == 1: print u"你输了..." num = num + 1 num_loss = num_loss + 1 break elif sel == 2: print u"你赢了!!!" num = num + 1 num_win = num_win + 1 break else: print u"输入错误,请重新输入" else: door.remove(choose_door) door.remove(luck_door) remove_door = random.choice(door) while True: sel = int(raw_input(str(remove_door)+ u'是错误的门,是否换至另一个门(1:是;2:否):')) if sel == 2: print u"你输了..." num = num + 1 num_loss = num_loss + 1 break elif sel == 1: print u"你赢了!!!" num = num + 1 num_win = num_win + 1 break else: print u"输入错误,请重新输入" con = raw_input(u'本次游戏结束,按任意键继续,退出请按输入x') if con == 'x': print u'胜利次数',num_win,u' 失败次数:',num_loss,u' 胜率:',float(num_win)/num break