Python3 计算出同花的概率
2018-07-20 来源:open-open
每次抽取后都重新洗牌。计算10000次随机抽取可得到同花的几率。我做的比较复杂,分别累计了四种花色分别出现了几次。
import random list=["2","3","4",'5','6','7','8','9','10',"J","Q","K","A"] list2=["H","C","D","S"] list3=[] n=0 a=0 while a<4: n=0 while n<13: list3+=[list[n]+list2[a]] n+=1 a+=1 i=0 r=0 d=0 c=0 s=0 h=0 while i <10000: random.shuffle(list3) list4=list3[0:5] i+=1 for card in list4: if 'D' in card: d+=1 if d==5: r+=1 for card in list4: if 'H' in card: h+=1 if h==5: r+=1 for card in list4: if 'S' in card: s+=1 if s==5: r+=1 for card in list4: if 'C' in card: c+=1 if c==5: r+=1 d=0 c=0 s=0 h=0 print ('Number of natural Flushes:',r) print('Percentage:',r/100,'%')
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐