三赌徒问题,赌徒问题,[Python]代码Py
三赌徒问题,赌徒问题,[Python]代码Py
[Python]代码
Python语言: 三赌徒问题"""http://spellscroll.com/questionfull/4/n=100; simulate(n)"""import randoma = 10; b = 10; c = 10fortune = [a,b,c]def one_round(): p = int(3*random.random()) for i in range(3): if i==p: fortune[i] += 2 else: fortune[i] -= 1def stop(): for i in fortune: if i==0: return True return Falsedef play_game(): global fortune fortune = [a,b,c]; cnt = 0 while not stop(): one_round(); cnt += 1 return cntdef simulate(n): cnt = [play_game() for i in range(n)] sum = reduce(lambda x,y: x+y, cnt, 0) return sum*1.0/n
相关内容
- python gtalk机器人,pythongtalk,[Python]代码Py
- 导出邮箱里的联系人:支持Gmail,126,网易,搜狐,H
- windows平台下如何用Python杀进程,平台python,[Python]代码
- Python中按月增加datetime,pythondatetime,[Python]代码Py
- python3 短网址和数字的相互转换,python3相互转换,impor
- 命令行从dict.cn查单词,命令行dict.cn单词,[Python]代码P
- python url格式解析,pythonurl解析,from urlpars
- python让图片按照exif信息里的创建时间进行排序,,impo
- python beautifulsoup抓取小说练习,,学习beautifuls
- Softmax Regression,softmaxregression,from numpy i
评论关闭