Question: In Simple python, we're creating classes for working with playing cards. All the cards you'll be creating here will have a rank-a number between 0
In Simple python, we're creating classes for working with playing cards. 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 - "royal" or "common". There's one card for every combination of rank, suit, and class, so there will be 60 cards in the deck.
Some cards are higher than others. 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. I.E., 2 of royal triangles is worth more than 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 that is written works as follows: 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. You'll be putting the definitions for the classes Card and Deck into a script called, and you'll be putting the game itself into a script. This means that your game script will have to import the Card and Deck class definitions with a command like from cards import Card,Deck.
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 an integer and two strings (e.g., Card(9, "Common", "SQUARES")). The constructor should not be case sensitive, and it shouldn't care whether or not the suit is plural.
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 card2.get_suit() should return "squares".
The class should have appropriate .__str__() and .__repr__() methods. 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.
Create a class definition for a Deck of Cards. A Deck should have one non-public attribute: a list of Cards. Your class definition should require following: The class must have a constructor that can take either a sequence of Cards (in this case, the Deck should have all of the Cards in the sequence), or a single card (in this case, the Deck will only have the one Card in it), or no arguments at all (in this case, the Deck should be initialized to a complete 60-card deck with one of each possible Card). The Deck class should have appropriate .__str__() and .__repr__() methods. Add a method called .shuffle() that randomizes the order of the Cards in the Deck's list. You'll probably want to use the shuffle() function from the random module. Add a method called .deal() that removes the first Card from the Deck and returns that Card.
Write a script that plays a round of our simplified version of game as described; In other words, your script must: Create a new Deck (a complete 60-card deck) and shuffle it (using the .shuffle() method you created. Deal a Card (using the .deal() method you wrote), and show that Card is to the player. Ask the player if they think the next card will be "higher" or "lower" than the next card. Deal the next Card (using .deal() again), and determine whether the player wins -they guessed correctly- or loses -they guessed wrong. Use > or < to determine which card is "higher" or "lower".
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
