Question: < < Python language >> Question 1 : Consider the PokerCard class given below: class PokerCard: def __init__(self, item): self.card = item self.value = self.__evaluate(item)

<< Python language >>

Question 1 :

Consider the PokerCard class given below:

class PokerCard: def __init__(self, item): self.card = item self.value = self.__evaluate(item) def __evaluate(self, item): #complete this 

Complete the __evaluate method which takes a String as a parameter and evaluates the value of a card. We use a two-character string to represent a card. For example: "2S" means "Two of Spades". We have "A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K" for values and "S, H, C, D" for the suits.

Write the PokerCard class in the answer box below. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks.

For example:

Test Result
a_card = PokerCard('2S') print (a_card.value)
2
cards = ['AS', 'AH', 'AC', 'AD'] for i in range(4): newcard = PokerCard(cards[i]) print (newcard.value, end=' ') 
11 11 11 11 

Question 2:

Starting with your solution to the previous task (or re-typing it all if you are keen!), extend the PokerCard class by adding the method __str__(self).

The __str__ method returns a two-character string to represent a card. For example: "2S" means "Two of Spades". We have "A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K" for values and "S, H, C, D" for the suits.

Write the complete PokerCard class in the answer box below. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks.

For example:

Test Result
a_card = PokerCard('2S') print (a_card)
2S
cards = ['AS', 'AH', 'AC', 'AD'] for i in range(4): newcard = PokerCard(cards[i]) print (newcard, end=' ') 
AS AH AC AD 

Question 3 :

The class "Deck" is defined for the initial deck of 52 cards. A stack ADT is used to store 52 poker cards. Consider the Deck class given as below:

class Deck: def __init__(self): self.cards = Stack() cardlist = ['AS', 'AH', 'AC', 'AD', '2S', '2H', '2C', '2D', '3S', '3H', '3C', '3D', '4S', '4H', '4C', '4D', '5S', '5H', '5C', '5D', '6S', '6H', '6C', '6D', '7S', '7H','7C', '7D', '8S', '8H', '8C', '8D', '9S', '9H', '9C', '9D', 'TS', 'TH', 'TC', 'TD', 'JS', 'JH', 'JC', 'JD', 'QS', 'QH', 'QC', 'QD', 'KS', 'KH', 'KC', 'KD'] for i in range(52): #complete this 

Complete the constructor "__init__" of the Deck class to create a deck with 52 cards.

Write the Stack class, PokerCard class, and Deck class in the answer box below. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks.

For example:

Test Result
Gdeck = Deck() print(Gdeck.cards.size()) print(Gdeck.cards.pop())
52 KD

class Stack:

class PokerCard:

class Deck:

Question 4 :

Starting with your solution to the previous task (or re-typing it all if you are keen!), extend the Deck class by adding the __str__ method.

The __str__ method returns a string to represent the deck. You should print all 52 cards by 4 rows.

Write the Stack class, PokerCard class, and Deck class in the answer box below. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks.

For example:

Test Result
Gdeck = Deck() print(Gdeck)
AS AH AC AD 2S 2H 2C 2D 3S 3H 3C 3D 4S 4H 4C 4D 5S 5H 5C 5D 6S 6H 6C 6D 7S 7H 7C 7D 8S 8H 8C 8D 9S 9H 9C 9D TS TH TC TD JS JH JC JD QS QH QC QD KS KH KC KD

class Stack:

class PokerCard:

class Deck:

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!