-1

I'm making a simple poker game to print the probability of getting: 1 pair, then 2 pair, then 3 of a kind and 4 of a kind.

What I want to do is make it where we have the user who gets a hand of 5 cards.

Then have it where you traverse through the list to check if each card matches with any of the other cards and to check if it's one pair, two pair, three of a kind, then four of a kind.

Then lastly checking the probability of getting those hands.

I'm just trying to get this started, I'm not sure what method to use to check if any two elements are equal then if there are two pairs then 3 and 4 of a kind.

For each, if-statement I know to use a break and return false so it'll end the while loop.

I am using 1-13 instead of using a dictionary to check for suits.

So far I have just printed the random set for the cards.

def poker():
    count = 0
    cards = []
    while(True):
        for i in range(0,5):
            cards = random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13])
            if(cards[0] == cards[1,2,3,4]):
                 count+=1
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
l.m
  • 131
  • 1
  • 10
  • Im not sure if its a good idea to use .count or itll make the code too long checking each element. – l.m Sep 24 '19 at 17:38
  • @Prune my question is checking elements in the list if you read my description "I'm just trying to get this started, I'm not sure what method to use to check if any two elements are equal then if there are two pairs then 3 and 4 of a kind." – l.m Sep 24 '19 at 17:49
  • 1
    Yes, I read your question. Please read the introductory tour, especially the portions to which I linked. You have some work to do before you have a question within the scope of Stack Overflow. – Prune Sep 24 '19 at 17:54
  • @Ahndwoo not sure why its not tagging just responded to you is it easier to talk in a chat? – l.m Sep 24 '19 at 20:32

1 Answers1

1

Here's a quick modification to your current code:

def poker():
    cards = []
    for i in range(5): #This is the same as range(0,5)
        # Use 'append' instead of '=' to add the new card to list instead of overwriting it
        cards.append(random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13])) 
    # set() will give you a set of unique numbers in your hand
    # If you have a pair, there will only be 4 cards in your set!
    for card in set(cards):
        number = cards.count(card) # Returns how many of this card is in your hand
        print(f"{number} x {card}")

Output:

"1 x 2"
"1 x 6"
"2 x 8" # <-- Pair!
"1 x 10"

This should get you on the right track! Now that you can tell how many of each card you have in your hand, you can use that to track each player's hand!

If you have any further, specific questions relating to a piece of code, feel free to ask another question, after brushing up on the question guidelines.

Ahndwoo
  • 1,025
  • 4
  • 16
  • That helped alot just needed a guide to start the problem! So i understand the concept – l.m Sep 24 '19 at 18:57
  • So now once i set up the statements for checking the number if its 2, 3, 4 so 2 being one pair then 3 being a three of a kind and 4 being four of a kind. What can i do to make a loop to continuously go through until either a pair or 3 or 4 of a kind shows? Should i use a while loop? So then i can use count to make the probability – l.m Sep 24 '19 at 19:07
  • You can call `poker()` from a while loop and have it return `set(cards)`. From there, you can set conditions to `break` your `while` loop. – Ahndwoo Sep 25 '19 at 12:00