Short assignment: Cards

I’ve written some code below to simulate a deck of cards. There are four suits of cards: clubs, spades, diamonds, and hearts. In each suit, there are 13 card values: cards with numbers 1 through 10, the Jack (11), the Queen (12), and the King (13). A standard deck has 52 cards: one of each value, for each suit. (We ignore the Joker.)

Write two classes: the Card class, and the Deck class. I wrote some simple code to test the classes. I’ve included the test code, but I have not given you the code for the classes. Write the classes so that my test code works, and so that the output is exactly as described in the comments of the test code.

A few hints. First, you can use the randint(min, max) function to pick a random number between min and max, inclusive of both min and max. Second, you can reorder (shuffle) a list by looping over the list, swapping each item into a random location. Third, the method pop removes the last item from a list and returns the value of that item. Finally, to see what methods you must write, you will have to read the test code carefully. You are welcome to write other methods if you need to do so. When you are done writing the classes, I advise you to step through the test code, making sure output is exactly what is expected.

card = Card(5, 1)
# prints "5 of clubs"
print(card)

card = Card(12, 4)
# prints "Queen of hearts"
print(card)

print("----")

deck = Deck()
# Add the 52 standard cards to the new deck
deck.add_standard_cards()

# Reorder the cards in the deck randomly.
#  The shuffle method makes use of the randint function
deck.shuffle()

# Create a new tiny Deck of cards called hand, made up
#   of the last five cards in deck.  The deal method should
#   also remove those last five cards from "deck".
hand = deck.deal(5)

# print the cards in the hand
for card in hand.card_list:
    print(card)

print("----")

# print the remaining cards in the deck
for card in deck.card_list:
    print(card)