Poker card in Python Let the CarteBase class present itself in the context of this exercise. It encapsulates a game card characterized by numerical values for its face and its kind. The possible faces are integers from 1 to 13, with face 1 corresponding to the ace, and faces 11, 12 and 13 corresponding respectively to the jack, the queen and the king. The other faces are simply identified by their number from 2 to 10. The possible grades are integers from 1 to 4 corresponding respectively to the cards of spade, heart, tile and clover. Analyze this class to understand how it works. You are asked to create a class called CarteDePoker that inherits CarteBase and defines or redefines the following methods: force(self) which returns the strength of the card in the poker game. In Poker, cards have the strength of their digital face from 2 to 13, except for the ace which is stronger than the other cards. So we give it a strength of 14. __eq__(self, other) to define operator behavior ==. __lt__(self, other) to define operator behavior <. __le__(self, other) to define operator behavior <=. __gt__(self, other) to define operator behavior >. __ge__(self, other) to define operator behavior >=. __ne__(self, other) to define operator behavior!=. Note that in Poker, a card is considered inferior to another card if the value of its strength is strictly inferior, or if its strength is equal, but its kind is numerically superior (i.e. pic > heart > tile > clover). Moreover, two cards are equivalent if their face and their kind are the same. Note also that only these first two (2) operators need to be defined from the attributes of the card, the other four can be deduced generically from < and ==. For example, we can define a <= b as the equivalent of a < b or a == b. To implement your class, be sure to use the basic class methods whenever possible (don’t reinvent the wheel), and be sure not to change the wheel.   This is what I have to start: 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 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

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

Poker card in Python
Let the CarteBase class present itself in the context of this exercise. It encapsulates a game card characterized by numerical values for its face and its kind. The possible faces are integers from 1 to 13, with face 1 corresponding to the ace, and faces 11, 12 and 13 corresponding respectively to the jack, the queen and the king. The other faces are simply identified by their number from 2 to 10. The possible grades are integers from 1 to 4 corresponding respectively to the cards of spade, heart, tile and clover. Analyze this class to understand how it works.

You are asked to create a class called CarteDePoker that inherits CarteBase and defines or redefines the following methods:

force(self) which returns the strength of the card in the poker game. In Poker, cards have the strength of their digital face from 2 to 13, except for the ace which is stronger than the other cards. So we give it a strength of 14.
__eq__(self, other) to define operator behavior ==.
__lt__(self, other) to define operator behavior <.
__le__(self, other) to define operator behavior <=.
__gt__(self, other) to define operator behavior >.
__ge__(self, other) to define operator behavior >=.
__ne__(self, other) to define operator behavior!=.
Note that in Poker, a card is considered inferior to another card if the value of its strength is strictly inferior, or if its strength is equal, but its kind is numerically superior (i.e. pic > heart > tile > clover). Moreover, two cards are equivalent if their face and their kind are the same. Note also that only these first two (2) operators need to be defined from the attributes of the card, the other four can be deduced generically from < and ==. For example, we can define a <= b as the equivalent of a < b or a == b.

To implement your class, be sure to use the basic class methods whenever possible (don’t reinvent the wheel), and be sure not to change the wheel.

 

This is what I have to start:

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 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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
User Defined DataType
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.
Similar questions
  • SEE MORE QUESTIONS
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