jeudi 29 octobre 2020

Creating a deck cards that can be shuffled and dealt using a class [closed]

I'm working on a task where I have to create a class that represent a deck with up to 52 different playing cards. The deck of cards should be represented as the rankings:

ranking = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]

The suits of the cards are represented as the classic Clover, Diamond, Heart and Spade, as shown here:

suite = ["C", "D", "S", "H"]

The class should be built in this way:

class  Deck:
    def  __init__(self):
        ...
    def  hand(self , n):
        ...
    def  deal(n, p):
        ...
    def  __str__(self):
        ...

The cards dealt should be represented in the way as example: seven of diamonds is represented as the string "D7". Every time an object of this class is created, it will will contain all 52 cards as a list. This list will be shuffled. The method hand in the class should deal n cards from the deck and returns them as a list. The cards dealt should be removed from the main deck. The method deal should deal out an amount of hands (p) of n cards. This should return a list of a list. The method str should return the cards in the current deck in the order they are currently shuffled.

I'm uncertain what code should be written in the different methods to get this to work. Since I am struggling quite a bit all help is welcome.




Aucun commentaire:

Enregistrer un commentaire