Isaac H.

asked • 12/21/22

Write the definition of a class named "Card" which creates a card from a standard deck of cards.

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()

Michael M.

This isn't a question so much as it's a request for someone to either help with your assignment or to do your assignment for you. I would recommend hiring a tutor to assist with this, as it's not something that can be answered in a simple response (without literally doing your assignment for you).
Report

12/23/22

Judy R.

Hello I am 22 years experienced Online Tutor and Assignment Helper for Computer Science and Math. I have been teaching IT Professionals, students from different grades, and Graduate and Post Graduate students for more than 22 years. I am ready to help you with your learning requirements, assignments, tests, and projects. For further discussion about the assignment or project help you need, please add me on skype and my skype id is nettuitions Thanks
Report

01/22/23

2 Answers By Expert Tutors

By:

Kevin S. answered • 12/25/22

Tutor
5.0 (379)

Experienced Computer Science Tutor: 20 Years Experience

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.