Question: NEED HELP IN PYTHON #Please design two classes as follows: 1. Please create a class called PlayingCard. This class should have: An attribute, rank that
NEED HELP IN PYTHON
#Please design two classes as follows:
1. Please create a class called PlayingCard. This class should have:
An attribute, "rank" that takes a value of 2-10, J, Q, K, or A. An attribute, "suit" that takes a value of "" "" "" or "". (If you don't know how to make these characters you can cut and paste from this block)
An init function
2. Please create a class called Deck. This class should have:
An attribute, "cards", that holds a list of PlayingCard objects. An init function that:
By default stores a full deck of 52 playing card (with proper numbers and suits) in the "cards" list. Each cards will be of the class PlayingCard above Allows the user to specify a specific suit (of the 4 - "" "" "" or ""). In this case, the program should only populate the deck with the 13 cards of that suit. After the cards object is initialized, call the "shuffle_deck()" function (below). A "shuffle_deck()" function that randomly changes the order of cards in the deck.
A "deal_card(card_count)" function that removes the first X cards from the deck and returns them as a list. Make sure this function gives an appropriate response when the deck is out of cards.
3. You might have to write __str__ or __repr__ methods to display the cards correctly.
Example:
>>> card1 = PlayingCard("A", "") >>> print(card1) A of
>>> card2 = PlayingCard(15, "") Invalid rank!
>>> card2 = PlayingCard(10, "bunnies") Invalid suit!
>>> deck1 = Deck() >>> print(deck1.cards) [K of , A of , 6 of , 7 of , J of , 6 of , Q of , 5 of , 10 of , 2 of , 8 of , 8 of , 4 of , 7 of , 3 of , K of , 9 of , 4 of , 10 of , 10 of , A of , 9 of , 7 of , 9 of , 7 of , 5 of , 3 of , 10 of , Q of , J of , 5 of , K of , K of , 2 of , 8 of , Q of , 3 of , 6 of , 6 of , A of , A of , 3 of , J of , 4 of , 5 of , 2 of , 4 of , 2 of , Q of , J of , 8 of , 9 of ]
>>> deck2 = Deck('') >>> deck2.shuffle_deck() >>> print(deck2.cards) [A of , 10 of , 3 of , 7 of , 5 of , 4 of , 8 of , J of , 9 of , Q of , 6 of , 2 of , K of ]
>>> deck2.deal_card(7) [A of , 10 of , 3 of , 7 of , 5 of , 4 of , 8 of ]
>>> deck2.deal_card(7) Cannot deal 7 cards. The deck only has 6 cards left!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
