- Provide extensive documentation for the class and methods.
- Do not import any packages other than random, even if you don’t use those.
1. Implement the class for the card deck. In particular, you should implement the shuffle() method and the get_card(rank, suit) method. The shuffle() method works precisely like the permute() function we talked about in class, except that it's a method. The get_card(rank, suit) should return the card having the corresponding rank (0 is clubs, 1 is diamonds, 2 is hearts, and 3 is spades) and suit (0 is 2, 1 is 3,..., 12 is Ace). You may also modify or add whatever method necessary to the Deck class. (5 points). 2. Complete the main() function that will shuffle the deck 10 times, and prints out the deck content each time it's shuffled. The printout format should be as follows: Card1: 2, Card2: A., ... You may modify appropriate parts of the Deck class to achieve this. (4 points)
ANM4 in 672222222 import random # Don't modify the Card class class Card: def __init__(self, n): self._id = n self.suit_sym= ['\u2663', '\u2666', '\u2665', '\u2660'] self.rank_sym= ['2', '3', '6', '7', '8', '9', '10', '3', '0', 'K', 'A'] def suit(self): return self._id // 13 def rank(self): return self._id% 13 def _repr_(self): return self.rank sym[self.rank()] + self.suit_sym[self.suit()] class Deck: # You're allowed to modify the constructor. definit__(self): # TODO: Define the necessary methods def shuffle(self): 28 *** 29 30 def get_card(self, rank, suit): 31 32 33 def main(): 34 # TODO: Write a code that will shuffle the deck 10 times, and for each shuffle, print out the deck. # Deck printout format: 'Card 1: , Card 2: , ..., where is the card printout. 35 36 37 38 _main__': if name main() 39 40 1 2 3 5 8 9 10 11 12 13 14 15 16 17 18 19 20 21 23 24 25
- Provide extensive documentation for the class and methods. - Do not import any packages other than random, even if you
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am