Question: Here's the task: And here's my code, please correct it, thank you! def main(): class PlayingCard: def __init__(self, rank, suit): Indicates rank from 1-13, as

Here's the task:

 Here's the task: And here's my code, please correct it, thank

And here's my code, please correct it, thank you!

def main():

class PlayingCard: def __init__(self, rank, suit): "Indicates rank from 1-13, as well as the card's suit." self.rank = rank self.suit = suit self.ranks = [None, "ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king"] self.suits = {"s": "spades", "d": "diamonds", "c": "clubs", "h": "hearts"} if rank 13: rank = 13

def get_rank(self): #Returns the rank of the card. return self.rank

def get_suit(self): #Returns the suit of the card. return self.suit

def bj_value(self): #Returns the Blackjack value of the card. if self.get_rank()

def __str__(self): #Returns a string that names the card. rank_str = self.ranks[self.rank] suit_str = self.suits[self.suit] return "{0} of {1}"." (self.ranks[self.rank], self.suits.get(self.suit))

def bj_value(self): #Returns the value of the card. return 0 def _repr_(self): if __name__ == '__main__': main()

Implement a class representing a playing card, and name it PlayingCard. These class methods are required 1 -init-self, rank, suit): This is your class initializer o rank is an int value that ranges from 1-13 (Ace, 2, 3,..., King.) suit is a single character "d", "c", "h", "s" representing each suit a card could possibly have (Diamonds, Clubs, Hearts, or Spades) get rank(self): When called on an instance of your PlayingCard class, it will return the rank of that particular card as an integer from 1-13 (Ace, 2, 3, ..., King.) o 2 3 get suit(self): When called on an instance of your PlayingCard class, it will return the suit of that particular card as single-character string of either "d", "c", "h", "s", where the letters represent Diamonds, Clubs, Hearts, or Spades, respectfully 4 bj value(self): When called on an instance of your PlayingCard class, it will return the Blackjack value of that particular card as an integer 5 repr This one allows any instance of your class to properly describe itself when you attempt to, say, print an object representing an instance of your class PlayingCard sample output: First, define your PlayingCard class, but don't yet define main(). Tell IDLE to load your program. Once program is loaded, and you are at the >>> prompt, you can test your class, directly: >>> c = PlayingCard(1,"s") >>print(c) Ace of Spades Try making a Queen of Clubs card: >>> c2 = PlayingCard(12,"c") >>>print(c2) Queen of Clubs >>c2.bj_value) 10 >c2.get_rank) 12 >c2.get_suit) c' Let's see how your program is require to run. This is what your main() should do (printing the PlayingCard instance and it's Blackjack value) Testing card class How many cards would you like to see? 5 Two of Hearts counts 2 King of Hearts counts 10 Ten of Spades counts 10 Five of Hearts counts 5 Ace of Diamonds counts 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!