Question: Write a python program which defines a class Deck. The program will randomly pulls a card from a deck of cards and will display its

Write a python program which defines a class Deck. The program will randomly pulls a card from a deck of cards and will display its rank and suit. Define the following two sets as class attributes:

ranks = {'2','3','4','5','6','7','8','9','10','J','Q','K','A'}

suits = {'\u2660', '\u2661', '\u2662', '\u2663'}

The suits set contains codes for the diamonds, spades, clubs, and heart. Printing any of these codes will print the corresponding icon.

Create a deck of 52 cards where each card has a rank and a suit (rank, suit).

This class besides the constructor has two functions of shuffle() and deal(). For shuffling the deck you can use the random.shuffle() function of the random library.

The user after defining a variable (e.g. deck1) as class Deck, can shuffle deck1, and then deal a card. Printing the result of the deal will show the rank and suit of the card.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!