Question: class Card (object): cardtype = 'Staff' class Player(object): def __init__(self, deck, name): Initialize a Player object. A Player starts the game by drawing 5 cards

class Card(object): cardtype = 'Staff'

class Player(object): def __init__(self, deck, name): """Initialize a Player object.

A Player starts the game by drawing 5 cards from their deck. Each turn, a Player draws another card from the deck and chooses one to play.

>>> test_card = Card('test', 100, 100) >>> test_deck = Deck([test_card.copy() for _ in range(6)]) >>> test_player = Player(test_deck, 'tester') >>> len(test_deck.cards) 1 >>> len(test_player.hand) 5 """ self.deck = deck self.name = name implement the draw and play methods in the Player class. The draw method draws a card from the deck and adds it to the player's hand, and the play method removes and returns the card from the player's hand at the given index.

def draw(self): """Draw a card from the player's deck and add it to their hand.

>>> test_card = Card('test', 100, 100) >>> test_deck = Deck([test_card.copy() for _ in range(6)]) >>> test_player = Player(test_deck, 'tester') >>> test_player.draw() >>> len(test_deck.cards) 0 >>> len(test_player.hand) 6 """ assert not self.deck.is_empty(), 'Deck is empty!' "*** YOUR CODE HERE ***"

! I need help here !

def play(self, card_index): """Remove and return a card from the player's hand at the given index.

>>> from cards import * >>> test_player = Player(standard_deck, 'tester') >>> test_player.hand = [james, jen, mitas, tammy] >>> test_player.play(0) is james True >>> test_player.play(2) is tammy True >>> len(test_player.hand) 2 """ "*** YOUR CODE HERE ***"

def display_hand(self): """ Display the player's current hand to the user. """ print('Your hand:') for card_index, displayed_card in zip(range(len(self.hand)),[str(card) for card in self.hand]): indent = ' '*(5 - len(str(card_index))) print(card_index, indent + displayed_card)

def play_random(self): """ Play a random card from hand. """ return self.play(random.randrange(len(self.hand)))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!