mardi 24 septembre 2019

Python probability of a pair

I am trying to make a poker game where it would check if it is a pair or three of a kind or four of a kind.

I am trying to figure out where to insert a while loop. if I should put it in front of the for card in set(cards): statement or the for i in range(5): I want to keep printing 5 cards until it shows either a pair, 3 of a kind, or 4 of a kind.

Then what I want to do is to print the probability of printing one of those options

import random
def poker():
    cards = []
    count = 0
    for i in range(5):
        cards.append(random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13]))
        print(cards)
    for card in set(cards):
        number = cards.count(card) # Returns how many of this card is in your hand
        print(f"{number} x {card}")
        if(number == 2):
            print("One Pair")
            break
        if(number == 3):
            print("Three of a kind")
            break
        if(number == 4):
            print("Four of a kind")
            break



Aucun commentaire:

Enregistrer un commentaire