Python three card poker

Using the card dictionary, deal out three cards. Determine the following:
(a) If the three cards form a flush (all of the same suit)
(b) If there is a three-of-a-kind (all of the same value)
(c) If there is a pair, but not three-of-a-kind
(d) If the three cards form a straight (all in a row, like (2, 3, 4) or (10, Jack, Queen))


from random import shuffle
deck = [{
'value':i, 'suit':c} for c in ['spades', 'clubs', 'hearts', 'diamonds'] for i in range(2, 15)]

shuffle(deck)
player = []

print(deck[0]['value'])
print(deck[0]['suit'])
num =
0

while num <= 1000:
   
for i in range(3):
        shuffle(deck)
       
if ((deck[0]['value'], deck[0]['suit'])) not in player:
            player.append((deck[
0]['value'], deck[0]['suit']))
       
else:
            player.append((deck[
0]['value'], deck[0]['suit']))
   
print(player)
   
if player[0][1] == player[1][1] == player[2][1]:
       
print('flush')
   
if player[0][0] == player[1][0] == player[2][0]:
       
print('three-of-a-kind')
   
if player[0][0] == player[1][0] or player[0][0] == player[2][0] or player[1][0] == player[2][0]:
       
print('pair')
    t = player[
0][0] + 1
   
p = player[0][0] + 2
   
if t == player[1][0] and p == player[2][0]:
       
print('straight')
       
break
   
player = []
    num +=
1

SOLUTION

[(9, 'clubs'), (9, 'hearts'), (9, 'spades')]
three-of-a-kind
[(
5, 'diamonds'), (2, 'diamonds'), (5, 'clubs')]
pair
[(
3, 'diamonds'), (9, 'diamonds'), (8, 'diamonds')]
flush
[(
10, 'hearts'), (11, 'hearts'), (12, 'spades')]
straight

Коментари

Популарни постови са овог блога

Python Fan functions

Python StopWatch milliseconds

Python game Jotto