PYTHON QUESTION I need someone can explain me step by step The following is the code given ---From here---- import rand
Posted: Thu Jun 02, 2022 8:03 am
PYTHON QUESTION
I need someone can explain me step by step
The following is the code given
---From here----
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', '4', '5',
'6', '7', '8', '9', '10', 'J', 'Q', '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.
def __init__(self):
...
# TODO: Define the necessary methods
def shuffle(self):
...
def get_card(self, rank, suit):
...
def main():
# TODO: need a code that will shuffle the deck 10
times, and for each shuffle, print out the deck.
# Deck printout format: 'Card 1: <X>, Card 2:
<Y>, ...', where <X> is the card printout.
...
if __name__ == '__main__':
main()
Instructions: Complete the following problems and submit the implementation by the due date. No late submissions will be accepted. This is an individual assignment, and every answer you submit should be of your own. Do not import any packages. Failure to adhere to the deliverable specification will result in a deduction of points. 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)
Provide extensive documentation for the class and methods. ● Do not import any packages other than random, even if you don't use those.
I need someone can explain me step by step
The following is the code given
---From here----
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', '4', '5',
'6', '7', '8', '9', '10', 'J', 'Q', '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.
def __init__(self):
...
# TODO: Define the necessary methods
def shuffle(self):
...
def get_card(self, rank, suit):
...
def main():
# TODO: need a code that will shuffle the deck 10
times, and for each shuffle, print out the deck.
# Deck printout format: 'Card 1: <X>, Card 2:
<Y>, ...', where <X> is the card printout.
...
if __name__ == '__main__':
main()
Instructions: Complete the following problems and submit the implementation by the due date. No late submissions will be accepted. This is an individual assignment, and every answer you submit should be of your own. Do not import any packages. Failure to adhere to the deliverable specification will result in a deduction of points. 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)
Provide extensive documentation for the class and methods. ● Do not import any packages other than random, even if you don't use those.