看看python是如何解决三赌徒问题的,python赌徒,关于Python语言的三
看看python是如何解决三赌徒问题的,python赌徒,关于Python语言的三
关于Python语言的三赌徒问题是如何解决的呢?就来看看下面这段关于python是如何解决三赌徒问题的源代码吧。(供参考!)
Python random模块使用方法。
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 cnt#www.iplaypy.comdef 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源代码,python源代码,下面
- 从糗事百科下载数据的python方法示例,糗事python,从糗事
- 下载序列并保存到文本中的方法,序列保存文本方法
- Python方法生成华容道所有开局,python华容道开局,编橙之
- world统计用python实现的方法,worldpython,python实现统计w
- 用Python语言打印杨辉三角形方法示例,python杨辉,下面这
- python猜数字游戏快速求解解决方案,python猜数字求解
- python计算文字的Md5和Sha1的校验值,,Python完成计算文字
- Python方法完成农历日历功能代码,python农历,Python方法完
- Python编写的点灯小游戏代码,python点灯小游戏,Python语言
评论关闭