I'm trying to make a 5 card poker game, and I'm trying to make a card_draw function that doesn't give duplicate cards, but I'm running into problems when trying to check if the randomly drawn card has already been drawn.
from random import choice
class standard_card:
def __init__(self, value, suit):
self.value = value
self.suit = suit
self.card = value + ' of ' + suit
def val():
values = ['Ace','2','3','4','5','6','7','8',
'9','10','Jack','Queen','King']
return choice(values)
def suits():
suit = ['Spades','Hearts','Clubs','Diamonds']
return choice(suit)
def card_draw(player_hand,nogo):
for i in range(5):
draw = standard_card(val(),suits())
while draw in nogo:
draw = standard_card(val(),suits())
player_hand.append(draw)
nogo.append(draw)
nogo = []
player_hand = []
card_draw(player_hand,nogo)
So in def card_draw() I'm just trying to make sure that the same card is not drawn twice, which is why I have while draw in nogo:.
However, while draw in nogo is always False, meaning sometimes a duplicate card is put into player_hand and nogo.
I don't understand why draw in nogo is always False. For example, if I do:
test_card = standard_card('7','Spades')
and one of the cards in nogo generated through card_draw() also happens to be given the value '7' and 'Spades',
test_card in nogo
is always False. Could someone explain why please?