Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions