from random import choiceclass PlayingCards: suits = ['Diamond','Club','Heart','Spade'] numbers = [x for x in range(2,11)] + list('JQKA') def __init__(self): self.main_deck = [[number,suit] for number in self.numbers for suit in self.suits] self.drawed_card = [] self.drawn_cards = [] def hit(self): if self.main_deck: self.drawed_card = self.main_deck.pop(choice(range(len(self.main_deck)))) self.drawn_cards.append(self.drawed_card) return self.drawed_card else: return Noneclass PlayerHand(PlayingCards): def __init__(self): super().__init__() self.player_drawn_cards = [] def hit(self): if self.main_deck: self.drawed_card = self.main_deck.pop(choice(range(len(self.main_deck)))) self.player_drawn_cards.append(self.drawed_card) return self.drawed_card else: return Nonecards = PlayingCards()player1_cards = PlayerHand()cards.hit()print(len(cards.main_deck))player1_cards.hit()print(len(cards.main_deck))
I'm trying to create a separate list which contains the card drawn by the player himself as well as the dealer which I will be adding further down this small project of mine.
When I ran the code above, the output for both print(len(cards.main_deck))
and print(len(cards.main_deck))
is 51. Shouldn't it be 50 since I called the hit()
method twice?