用py写一个关于斗牛各种牌型出现概率的程序

直接上代码吧
import random
import itertools
class poker():
def init(self):
self.paiku = [1,2,3,4,5,6,7,8,9,10,10,10,10]*4
def run(self):
res = []
s = list(itertools.combinations(self.paiku,5))
for i in s:
#print(i)
k = list(itertools.combinations(i,3))
for j in k:
if sum(j) == 10 or sum(j) == 20 or sum(j) == 30:
res.append(sum(i)%10)
break
else:
res.append(10)
return res
def show_res(self):
res = self.run()
print(“1:{}”.format(res.count(1)/len(res)))
print(“2:{}”.format(res.count(2)/len(res)))
print(“3:{}”.format(res.count(3)/len(res)))
print(“4:{}”.format(res.count(4)/len(res)))
print(“5:{}”.format(res.count(5)/len(res)))
print(“6:{}”.format(res.count(6)/len(res)))
print(“7:{}”.format(res.count(7)/len(res)))
print(“8:{}”.format(res.count(8)/len(res)))
print(“9:{}”.format(res.count(9)/len(res)))
print(“10:{}”.format(res.count(0)/len(res)))
print(“0:{}”.format(res.count(10)/len(res)))
A = poker()
print(A.show_res())

你可能感兴趣的:(用py写一个关于斗牛各种牌型出现概率的程序)