so my goal is to try to simulate an actaul deck and draw five cards and check if there is a three of a kind. I have no problem making the deck and drawing five cards, the problem arises when i check for three of a kind

my code:

```from random import shuffle, sample
from itertools import product
#generating  deck
suits = ["s","d","h","c"]
values = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
deck = list(product(values,suits))
sim = 100000

three_of_a_kind = 0
for i in range(sim):
shuffle(deck)
#generating hand
hand = sample(deck,5)
#checking for three of a kind
if any(hand[0][0] == x[0] for x in hand):
three1 += 1
elif any(hand[1][0] == x[0] for x in hand):
three2 += 1
elif any(hand[2][0] == x[0] for x in hand):
three3 += 1
if three1 == 3 or three2 == 3 or three3 == 3:
three_of_a_kind += 1
prob_three = three_of_a_kind/sim
print(prob_three)
```

edit: my deck only had 12 cards and I changed it to 13 but my question has not changed

Mar 23, 2022 223 views

1 answer to this question.

from collections package import counter to count cards. The code is shown below;

```from random import shuffle, sample
from itertools import product
from collections import Counter
#generating  deck
suit = ["s","d","h","c"]
cards = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
value = list(product(cards,suit))
val = 100000

three_of_a_kind = 0
for i in range(val):
shuffle(values)

#generating hand
hand = sample(value,5)

# Check for 3 of a kind by checking for 3 cards of same value
if any(v==3 for k,v in Counter(card[0] for card in hand).items()):
three_of_a_kind += 1

prob_three = three_of_a_kind/val
print(f'{prob_three:.4%}')
```
answered Mar 25, 2022 by
• 5,480 points

Formula to calculate chance (probability) of a dice side based on its value

If I understand you correctly, you're looking ...READ MORE

How does software that calculates winning probability of a Texas Hold'em or Omaha hand against 8 random opponent hands work?

The projected win rate, as you noted, ...READ MORE

Create a Markov Model that can generate text simulations by studying Donald Trump speech data set.

The logic here is simple. Apply Markov Property ...READ MORE

Transition matrix to have percentages instead of default probability - Markov chain

While using Markov chain, is it possible ...READ MORE

how do i change string to a list?

suppose you have a string with a ...READ MORE

how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

how do i use the enumerate function inside a list?

Enumerate() method adds a counter to an ...READ MORE