Part I: Create Deck of Cards (10 points) Write a function create.deck () that cr
ID: 3716423 • Letter: P
Question
Part I: Create Deck of Cards (10 points) Write a function create.deck () that creates and returns alist of 52 Card objects in the order specified below. The function takes no arguments. A Card has a rank in the range 0 through 12 and a suite in the range 0 through 3. A card showing a 2 is represented by ID #0, 3 is represented by ID #1, , 10 is represented by ID #8; and the Jack, Queen, King and Ace are represented by 9, 10, 11 and 12, respectively: Rank Number Assigned 0 4 4 10 10 12 Suits are assigned ID numbers as follows: Number Assigned Suit CLUBS SPADES DIAMONDS 2 HEARTS3 For example, a Card that represents the Queen of Clubs will have 0 for its _suit attribute and 10 for its_rank attribute. The create.deck () constructs and returns a list of 52 Card objects. The cards are returned in the following order: » all of the Clubs in the order 2 through Ace, followed by » all of the Spades in the order 2 through Ace, followed byExplanation / Answer
def create_deck():
deck=[]
for i in range(4):
for j in range(12):
card=Card(i,j)
deck.append(card)
return deck
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.