尝试打印两对概率

问题描述 投票:-1回答:2

我正在尝试制作一个简单的扑克游戏,在该游戏中,我将模拟选项中显示的每只手作为一对,一对,两对,等等。

我正在尝试通过使用计数在每次发出新手时递增来打印出概率

def twopair():
    count = 0
    while True:
        cards = []
        for i in range(5):
            cards.append(random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]))
        stop = False 
        counted_cards = Counter(cards)
        two_most_common, count = zip(*counted_cards.most_common(2))

        count_to_message = {
            (1, 1): "Nothing",
            (2, 1): "One Pair",
            (3, 1): "Three of a Kind",
            (4, 1): "Four of a Kind",
            (5, 1): "Five of a Kind",
            (2, 2): "Two Pairs",
            (3, 2): "Full House",
        }

        msg = count_to_message[count]
        print(msg)
        if msg == "Two Pairs":
            stop = True
            break
        #else:
         #   count+=1
    #print(f'Count is {1/count}')

如果删除#,则会出现无法将元组与整数连接的错误。我可以做些什么来解决这个问题,以便进行计数,这样我就可以将计数除以1,从而得到两对的概率?

python poker
2个回答
0
投票

Couter.most_common()返回一个元组列表(元素,计数):https://docs.python.org/2/library/collections.html


0
投票

简单的print命令显示您已重载了变量count:您正试图将其用作卡计数的元组

© www.soinside.com 2019 - 2024. All rights reserved.