Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python- Please work it out rather than write on paper. THanks! Define a Deck class that upon construction, creates a list of 52 possible cards

Python- Please work it out rather than write on paper. THanks!

Define a Deck class that upon construction, creates a list of 52 possible cards and store them in a cards data attribute. Cards should be instances of the Card class created previously. You should import the class from that file and reuse it for solving this problem. The class should implement three methods as follows: shuffle(): should shuffle the deck and place cards in a random order. deal(): should return a card from the deck or raise a ValueError if none left in the deck. The returned card should be removed from the deck. remaining(): should print the number of remaining cards in the deck. For example, you should be able to create a deck as deck1 = Deck(). Then, you should be able to shuffle the deck by calling deck1.shuffle(). If you call deck1.remaining(), it should print Cards remaining in deck: 52. Then, if you call deck1.deal(), it should return a random card from the deck. Since the returned card is an instance of the class Card, you should be able to call the display() method on it and print its suit and value. Now, if you call deck1.remaining() again, it should print Cards remaining in deck: 51

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

Students also viewed these Databases questions

Question

What is management growth? What are its factors

Answered: 1 week ago