Question: All the cards you'll be creating here will have a rank (a number between 0 and 9), a suit(triangles, squares, or pentagons), and a class
All the cards you'll be creating here will have a rank (a number between 0 and 9), a suit(triangles, squares, or pentagons), and a class (either "royal" or "common"). There is exactly one card for every possible combination of rank, suit, and class, so there will be 60 cards in the deck.
Some cards are considered "higher" than other cards. Royal cards are always considered higher than common cards. If the classes are the same, then the suits determine which card is higher. Pentagons are higher than squares, and squares are higher than triangles. If both the suit and the class are the same, then the rank is used to determine which card is higher. So for example, the 2 of royal triangles is worth more than the 5 of common pentagons, which is worth more than the 8 of common squares, which is worth more than the 5 of common squares.
The game you'll be implementing is a simplified variant of a game called High-Low. Here's how it works:
A 60-card deck is shuffled and one card is dealt face up.
The player has to guess whether the next card dealt will be higher or lower than this card.
Once the player makes their guess, a second card is dealt. If they player was correct, then they win. If the player was wrong, then they lose.
Create a class definition for a playing Card. A playing card needs to store information about its suit, class, and rank. It's up to you to decide the specific details of how things will be represented internally, but to practice encapsulation, make sure that your attributes are all non-public. In addition:
The Card class should have a constructor that can take either three strings (e.g., Card("0","common","triangles") or Card("7","Royal","Pentagon")) or an integer and two strings (e.g., Card(9, "Common", "MOONS")). The constructor should not be case sensitive, and it shouldn't care whether or not the suit is plural.
This is very similar to what I did in the notes for a previous reading assignment.
There should be three accessor methods ("getters"): .get_rank() (which should return the rank as an integer), .get_suit() (which should return the suit as a string (plural, and in lowercase)), and .get_class() (which should return the class (in lowercase)). So for example, if you created a Card with the command card1 = Card(0, "common", "triangle"), then card1.get_rank() should return 0, card1.get_class() should return "common", and card1.get_suit()should return "triangles". Similarly, if you created a Card with the command card2 = Card("5", "Royal", "squares"), then card2.get_rank() should return 5, card2.get_class() should return "royal", and card1.get_suit()should return "squares".
The class should have appropriate .__str__() and .__repr__() methods. You can choose the details of formatting, but as always, the .__str__() method should produce a string suitable for displaying to the user*, and the .__repr__() method should produce a string that you could use as a Python command to create a Card.
*You have lots of options here. You could go with something descriptive (e.g., "7 of royal pentagons" or "0 of common squares"), or you could use the unicode escape sequences for the symbols representing pentagon, square, and triangle, and maybe using a crown for the royal class (e.g., "7" or "0"). Here are those escape sequences, if you want them: \u2302: (pentagon), \u25A1: (square), \u25B3: (triangle), \u265B: (crown).
You should be able to use == and != to compare Cards. Two Cards should be "equal" if they have the same rank, class, and suit.
You should be able to compare cards using >, <, >=, and <=. The "greater" card is the one that is "higher", according to the description at the top of this assignment.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
