April 2018
Beginner
340 pages
7h 54m
English
A Hand class will need to contain cards just like the Deck class does. It will also be assigned a value by the rules of the game based on which cards it contains.
Since the dealer's hand should only display one card, we also keep track of whether the Hand belongs to the dealer to accommodate this rule:
class Hand: def __init__(self, dealer=False): self.dealer = dealer self.cards = [] self.value = 0 def add_card(self, card): self.cards.append(card)
Much like the Deck, a Hand will hold its cards as a list of Card instances.
When adding a card to the hand, we simply add the Card instance to our cards list.
Calculating the value of a Hand is where the rules of the game come into play the most:
def calculate_value(self): self.value ...