Question: Q: Would like to know implement to this existing class and run it successfully. Class Hand ) Implement class Hand that represents a hand of
Q: Would like to know implement to this existing class and run it successfully.
Class Hand) Implement class Hand that represents a hand of playing cards. The class should have a constructor that takes as input the player ID (a string). It should support method addCard(). that takes a card as input and adds it to the hand and method showHand() that displays the players hand in the format shown.
class Deck:
'represents a deck of 52 cards'
# ranks and suits are Deck class variables
ranks = {'2','3','4','5','6','7','8','9','10','J','Q','K','A'}
# suits is a set of 4 Unicode symbols representing the 4 suits
suits = {'\u2660', '\u2661', '\u2662', '\u2663'}
def __init__(self):
'initialize deck of 52 cards'
self.deck = [] # deck is initially empty
for suit in Deck.suits: # suits and ranks are Deck
for rank in Deck.ranks: # class variables
# add Card with given rank and suit to deck
self.deck.append(Card(rank,suit))
def dealCard(self):
'deal (pop and return) card from the top of the deck'
return self.deck.pop()
def shuffle(self):
'shuffle the deck'
shuffle(self.deck)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
