Question

Now, create a Deck class that consists of 52 cards (each card is an instance of class Card) by filling in the template below. Represent the suit of cards as a string: Spades, Diamonds, Hearts, clubs and the rank of cards as a single character or integer: 2, 3, 4, 5, 6, 7, 8, 9, 10, J, class Deck: def init (self): pass # Your code here. def draw (self): Returns the card at the top of the deck, and removes it from the deck pass # Your code here. def shuffle (self): Shuffle the remaining cards in the deck. pass # Your code here. d Deck() card = d.araw() print(card.suit) print (card.rank) print (card .value()) # Pay attention to the brackets here. value() is a method, so we need to call it like one d.shuffle() card d.draw) print (card.suit) print(card.rank) print (card .value()) # Pay attention to the brackets here. value() is a method, so we need to call it like one

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import random
class Card:
    dictionary = {'A': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7,
                  '8': 8, '9': 9, '10': 10, 'J': 11, 'Q': 12, 'K': 13}
    def __init__(self, suit, rank):
        self.suit=suit
        self.rank=rank
    def value(self):
        return Card.dictionary[str(self.rank)]

class Deck:
    card_list=[]
    def __init__(self):
        for suite in ["Hearts", "Diamonds", "Spades", "Clubs"]:
            for key in Card.dictionary.keys():
                card1=Card(suite, key)
                Deck.card_list.append(card1)
                # print(card1.suit())

    def draw(self):
        x=Deck.card_list[0]
        card=Deck.card_list.remove(x)
        return x
    def shuffle(self):
        random.shuffle(Deck.card_list)
        return Deck.card_list
d=Deck()
card=d.draw()
print(card.suit)
print(card.rank)
print(card.value())

d.shuffle()
card=d.draw()
print(card.suit)
print(card.rank)
print(card.value())

Add a comment
Know the answer?
Add Answer to:
Now, create a Deck class that consists of 52 cards (each card is an instance of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT