''' DS2000 Fall 2024 Sample code from lecture - Deck class for a card game ''' import random from card import Card NUM_VALUES = 13 SUITS = ["clubs", "diamonds", "hearts", "spades"] class Deck: ''' class for a deck of cards. Attribute: list of Card objects Methods: init, shuffle, deal ''' def __init__(self): self.cards = [] self.make_deck() def make_deck(self): ''' create a deck of 52 cards (13 values x 4 suits)''' for i in range(NUM_VALUES): for j in range(len(SUITS)): c = Card(SUITS[j], i + 1) self.cards.append(c) def shuffle(self): ''' shuffle the cards by randomly swapping positions ''' for i in range(len(self.cards)): pos = random.randint(0, len(self.cards) - 1) self.cards[pos], self.cards[i] = self.cards[i], self.cards[pos] def deal(self): ''' deal a card by popping off the deck and returning it ''' if self.cards: return self.cards.pop() return None