Question: Need help with Intro to Comp Sci 2 (Python) problem: Add a Hand(object) class to the Card and Deck classes in the template. The __init__
Need help with Intro to Comp Sci 2 (Python) problem:
Add a Hand(object) class to the Card and Deck classes in the template. The __init__ has been written for you. Write a class program getHand() which will assign cards from the deck to the hand and remove those cards from the deck so they cannot be used again. See the output below for details on how it should look. Write a class program sneakPeek() which will allow you to see the hand from the topmost card (the last dealt) to the bottommost (the first dealt). Write an __iter__ and next for the Hand class used by sneakPeek().
Write a program playWar which will take as parameters two instances of type Hand. Taking from the top of each hand (top being the last one dealt), compare the ranks of both hands on a card by card basis. The higher rank is the winner. A count is kept of both hands wins and a winner is declared at the end of the game with details as shown in the sample output.
This is what is provided:


This is the sample output:


class Card (object) def init (self rank suit) FACE (CARD {11 'J', 12 'Q', 13 'K' self. suit Suit self. rank rank if rank 10 else FACE CARD rank] def str (self) return "Sass" (self. rank, self. suit) class Deck (object) def init (self, numCards 10) self. cards for s in C' S 'D', 'C', 'H' for r in range (1 numCards) c Card (r s) self. cards. append (c) class Hand (object) This sets up a deck prior to a deal You do not need to add anything to this unless you want to def init (self) self. d-Deck self. deck Cards self.d.cards This code takes cards from the deck randomly and saves them to a hand It removes from the deck any cards it uses It prints out the cards as they are being dealt def getHand (self,numInHand 5) pa 33 This code shows the cards beginning with the last dealt (the top) and ending with the first dealt (the bottom) def sneak Peek (self) pa 33 def iter (self) pa 33 def next (self) pa 33
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
