Write the definition of a class named "Card" which creates a card from a standard deck of cards. This class should have the following methods: __init__(self, rank, suit), getRank(self), getSuit(self), printCard(self), shuffle(self), and cheat(self, rank, suit).

• The suits are: "Hearts", "Diamonds", "Clubs", and "Spades".
• The ranks are: "Ace", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", and "King".
• getRank(self) and getSuit(self) return the rank and the suit of the card, respectively.
• printCard(self) prints the information on the card, like "This card is the Ace of Spades."
• shuffle(self) replaces the card with any card from the deck, chosen randomly.
• cheat(self, rank, suit) changes the rank and suit of the card to the input given in cheat.

The user should be able to do the following (also see template below):
c = Card("Ace", "Spade")
c.getRank()
"Ace"
c.getSuit()
"Spade"
c.printCard()
This card is the Ace of Spades.

c.shuffle()
c.printCard()
This card is the Ten of Diamonds. # Or any other random card

c.cheat("King", "Heart")
c.printCard()
This card is the King of Hearts.

c.cheat("12", "Spades")
c.printCard()
Invalid card

from random import choice

# Definition of class Card

# Note that the possible suits are ["Hearts", "Diamonds", "Clubs", "Spades"]
# The possible ranks are ["Ace", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"]

class Card:
def __init__(self, rank, suit):
self.rank =
self.suit =

def getRank(self):
# Enter your code here

def getSuit(self):
# Enter your code here

def printCard(self):
# Enter your code here

def shuffle(self):
# You will need a list of the possible suits and a list of the possible ranks to be able to shuffle
# Recall that the method choice(list) chooses a random element from the list.
# Enter your code here

def cheat(self, rank, suit):
# Enter your code here
# If you have time, you should check that the rank and suit entered are valid by checking if they are in the lists of possible ranks and suits.

c = Card("Ace", "Spade")
c.getRank()
c.getSuit()
c.printCard()

c.shuffle()
c.printCard()

c.cheat("King", "Heart")
c.printCard()

c.cheat("12", "Spades")
c.printCard()

Note: The program has to be written in the Python programming language!



Answer :

Other Questions