Question: In Python, Write a class Card which represents a card in a standard deck of 5 2 cards. Each card will have a suit and
In Python, Write a class Card which represents a card in a standard deck of cards. Each card will have a suit and a rank. The allowed suits are:
a Heart
b Spade
c Club
d Diamond
The allowed ranks are:
a to
b A
c K
d Q
e J
Constructor:
The card constructor will take two string arguments. The first argument will be a Suit and the second argument will be the Rank. You must verify that the Suit and Rank are valid based on the description given above. Raise ValueError exception if the suit or rank are not correct with the message indicating which one is incorrect.
Printing:
The card must print the suit and rank when the print function is called on the card. The example shows the exact requirement. Implement function required to achieve the printing
Comparisons:
The Card class must support equality and less than comparisons. For equality check, both suit and rank must match.
Less than check is only supported for cards of the same suit. If the suits differ then you must raise an IncompatibleSuitsError. You must define this exception.
For matching suits, the rank order is as follows:
JQKA where A is the highest rank and is the lowest rank.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
