Create a class called PaquetDeCartes that encapsulates a pack of 52 game cards. Inherit your class from the standard class list, and define the following methods: __init__(self, card, shuffle=False) which builds a pack of 52 cards by instantiating cards from the card class. For example, package = PaquetDeCartes(CarteBase), where the CarteBase class is defined in the context of this exercise. By default, cards must be in the order of ace to king, first for spades, then for hearts, then for tiles and finally for clovers. The optional mix argument (default=False) specifies that cards must be initially mixed. mix(self) which allows you to randomly mix the cards in the package. To do this, use the shuffle function of the random module. Draw(n) which returns the first n cards of the package to a list. Note that the cards drawn must be removed from the package and the number of cards returned cannot exceed the number of cards currently in the package. If the packet becomes empty, the method should simply return an empty list. Hints: To remove a card at the beginning of the package, you can use list.pop(0). Note that the constructor of your class must accept any card class that can instantiate from a face number and a kind number, as for the CarteBase class, or any class derived from that class. Be sure to use the list you inherit; do not create another list for your card pack.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Deck of cards in python
Create a class called PaquetDeCartes that encapsulates a pack of 52 game cards. Inherit your class from the standard class list, and define the following methods:

__init__(self, card, shuffle=False) which builds a pack of 52 cards by instantiating cards from the card class. For example, package = PaquetDeCartes(CarteBase), where the CarteBase class is defined in the context of this exercise. By default, cards must be in the order of ace to king, first for spades, then for hearts, then for tiles and finally for clovers. The optional mix argument (default=False) specifies that cards must be initially mixed.
mix(self) which allows you to randomly mix the cards in the package. To do this, use the shuffle function of the random module.
Draw(n) which returns the first n cards of the package to a list. Note that the cards drawn must be removed from the package and the number of cards returned cannot exceed the number of cards currently in the package. If the packet becomes empty, the method should simply return an empty list.
Hints: To remove a card at the beginning of the package, you can use list.pop(0).

Note that the constructor of your class must accept any card class that can instantiate from a face number and a kind number, as for the CarteBase class, or any class derived from that class. Be sure to use the list you inherit; do not create another list for your card pack.

Background to this exercise:

class CarteBase:
    names = {1: 'as', 11: 'jack', 12: 'lady', 13: 'king'}
    sorts = ['spade', 'heart', 'tile', 'clover']

    def __init__(self, m, n):
        assert 1 <= m <= 13 and 1 <= n <= 4
        self.numface = m
        self.numsort = n

    def __repr__(self):
        return f'{type(self). __name__}({self.numface}, {self.numsort})'

    def __str__(self):
        return f'{self.nom()} de {self.sorte()}'

    def __eq__(self, other):
        return self.numface == other.numface and self.numsorte == other.numsorte

    def name(self):
        # returns the name of the card for the ace, jack, queen and king,
        # otherwise the numerical value of its face (2 to 10)
        return CarteBase.noms.get(self.numface, str(self.numface))

    def sorte(self):
        # returns the kind of card (spade, heart, tile or clover)
        return CarteBase.kinds[self.numsort-1]

    def force(self):
        # returns the default force of the card (the numerical value of its face)
        return self.numface

 

Expert Solution
steps

Step by step

Solved in 6 steps with 4 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education