E Template 2 import random 3 4 vclass Card: def init__(self, value, suite): self.value - value 6 7. self.suite = suite 8 def str(self): return f"{self.value) of (self.suite}" 9 10 11 def -eq(self, other): "Check if two cards are the sane" = -- YOUR CODE HERE -- 12 13 14 15 16 vclass CardSet: def init(self): self.cards -[] 17 18 19 def view(self): for card in self.cards: print (card) 20 21 22 23 def add_cards (self, cards): "Add cards to your set""" # -- YOUR CODE HERE -- 24 25 26 27 28 vclass Deck(CardSet): 29 def init(self): ""Initialize the 52-card set. Start fron 1-11, then Jack, Queen, King, then by suite: clubs, spades, hearts, 30 dianonds"" 31 cards - [) = -- YOUR CODE HERE -- self.cards - cards 32 33 35 def count_cards (self): ""Count the number of cards in a deck"" = -- YOUR CODE HERE -- 36 37 38 def shuffle(self, seed-None): ""Shuffle your deck using a random seed" 39 40 41 random.seed (seed) = -- YOUR CODE HERE -- 42 43 44 def peek(self, number-5): ""Show the top n cards of the stack. This is analogous to getting the last n cards then reversing it.""" = -- YOUR CODE HERE -- 45 46 47 48 def draw(self, cardset, number-5): ""Transfer the top n cards of the stack to your cardset."" = -- YOUR CODE HERE -- 49 50 51 52 53 def add_cards (self): 54 pass 55 56 if name - "-main_": -- "-main": seed, hand, peek - input().split(",") 56 vif 57 58 myDeck - Deck() handA - CardSet () handB - CardSet () 59 60 61 62 63 myDeck.shuffle (int(seed)) 64 for x in range (1,3): print(f"\nRound (x}:") 65 66 67 68 myDeck.draw(handA, int (hand)) myDeck.draw(handB, int(hand)) 69 70 print ("Hand A: ") handA.view() print ("Hand B: ") handB.view() 71 72 73 74 75 myDeck.count_cards () if(x == 1) : 76 77 print(f"\n{peek} Cards at the top: ") myDeck.peek (int (peek)) 78 79

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

IN PYTHON:

In the code template below, you are given three classes: CardCardSet, and Deck.

The Card class has the attributes of value and suite, which describe the cards in a standard 52-card deck. The attribute value takes in the digits 1 to 10 as well as the standard face cards, Jack, Queen, and King. The suite attribute takes in the four suites, namely clubsspadeshearts, and diamonds. Obviously, two cards are equal if they have the same value and suite.

The CardSet class is just an ensemble of Card instances. To know which cards are in your set, just iterate through the cards via the view method. This gets a formatted list of your cards in the cards attribute. To add cards to your set, use the add_cards method.

The Deck class is a child class of the CardSet class. To initialize a deck, all 52 cards from the standard deck must be added to it. For uniformity, place each suite in ascending value -- 1 to 10, then Jack, then Queen, then King. The suites must be placed in this order: clubs - spades - hearts - diamonds.

NOTE: All the diamond-suited cards are at the top of the deck, while the clubs are at the bottom of the deck.

To visualize:

E Template
2 import random
3
4 vclass Card:
def init__(self, value, suite):
self.value - value
6
7.
self.suite = suite
8
def str(self):
return f"{self.value) of (self.suite}"
9
10
11
def -eq(self, other):
"Check if two cards are the sane"
= -- YOUR CODE HERE --
12
13
14
15
16 vclass CardSet:
def init(self):
self.cards -[]
17
18
19
def view(self):
for card in self.cards:
print (card)
20
21
22
23
def add_cards (self, cards):
"Add cards to your set"""
# -- YOUR CODE HERE --
24
25
26
27
28 vclass Deck(CardSet):
29
def init(self):
""Initialize the 52-card set. Start fron 1-11, then Jack, Queen, King, then by suite: clubs, spades, hearts,
30
dianonds""
31
cards - [)
= -- YOUR CODE HERE --
self.cards - cards
32
33
35
def count_cards (self):
""Count the number of cards in a deck""
= -- YOUR CODE HERE --
36
37
38
def shuffle(self, seed-None):
""Shuffle your deck using a random seed"
39
40
41
random.seed (seed)
= -- YOUR CODE HERE --
42
43
44
def peek(self, number-5):
""Show the top n cards of the stack. This is analogous to getting the last n cards then reversing it."""
= -- YOUR CODE HERE --
45
46
47
48
def draw(self, cardset, number-5):
""Transfer the top n cards of the stack to your cardset.""
= -- YOUR CODE HERE --
49
50
51
52
53
def add_cards (self):
54
pass
55
56 if name - "-main_":
-- "-main":
seed, hand, peek - input().split(",")
56 vif
57
58
myDeck - Deck()
handA - CardSet ()
handB - CardSet ()
59
60
61
62
63
myDeck.shuffle (int(seed))
64
for x in range (1,3):
print(f"\nRound (x}:")
65
66
67
68
myDeck.draw(handA, int (hand))
myDeck.draw(handB, int(hand))
69
70
print ("Hand A: ")
handA.view()
print ("Hand B: ")
handB.view()
71
72
73
74
75
myDeck.count_cards ()
if(x == 1) :
76
77
print(f"\n{peek} Cards at the top: ")
myDeck.peek (int (peek))
78
79
Transcribed Image Text:E Template 2 import random 3 4 vclass Card: def init__(self, value, suite): self.value - value 6 7. self.suite = suite 8 def str(self): return f"{self.value) of (self.suite}" 9 10 11 def -eq(self, other): "Check if two cards are the sane" = -- YOUR CODE HERE -- 12 13 14 15 16 vclass CardSet: def init(self): self.cards -[] 17 18 19 def view(self): for card in self.cards: print (card) 20 21 22 23 def add_cards (self, cards): "Add cards to your set""" # -- YOUR CODE HERE -- 24 25 26 27 28 vclass Deck(CardSet): 29 def init(self): ""Initialize the 52-card set. Start fron 1-11, then Jack, Queen, King, then by suite: clubs, spades, hearts, 30 dianonds"" 31 cards - [) = -- YOUR CODE HERE -- self.cards - cards 32 33 35 def count_cards (self): ""Count the number of cards in a deck"" = -- YOUR CODE HERE -- 36 37 38 def shuffle(self, seed-None): ""Shuffle your deck using a random seed" 39 40 41 random.seed (seed) = -- YOUR CODE HERE -- 42 43 44 def peek(self, number-5): ""Show the top n cards of the stack. This is analogous to getting the last n cards then reversing it.""" = -- YOUR CODE HERE -- 45 46 47 48 def draw(self, cardset, number-5): ""Transfer the top n cards of the stack to your cardset."" = -- YOUR CODE HERE -- 49 50 51 52 53 def add_cards (self): 54 pass 55 56 if name - "-main_": -- "-main": seed, hand, peek - input().split(",") 56 vif 57 58 myDeck - Deck() handA - CardSet () handB - CardSet () 59 60 61 62 63 myDeck.shuffle (int(seed)) 64 for x in range (1,3): print(f"\nRound (x}:") 65 66 67 68 myDeck.draw(handA, int (hand)) myDeck.draw(handB, int(hand)) 69 70 print ("Hand A: ") handA.view() print ("Hand B: ") handB.view() 71 72 73 74 75 myDeck.count_cards () if(x == 1) : 76 77 print(f"\n{peek} Cards at the top: ") myDeck.peek (int (peek)) 78 79
cards_in_deck = ["1 of clubs", "2 of clubs", ... "King of clubs", "1 of spades",
"2 of spades", ... "King of spades", "1 of hearts",
"2 of hearts", ... "King of hearts", "1 of diamonds",
"2 of diamonds", ... "King of diamonds"]
The cards inside a deck may also be shuffled. A seed argument is added for reproducibility. The peek method
of the class allow you to peek at the top n cards. The default value for nis 5.
Lastly, The draw method allows you to draw the top n cards of the deck and transfer these cards to a CardSet
instance. The default value of n is 5. Note that the number of cards that you can draw cannot exceed the
current number of cards in the deck.
In this exercise, you will simulate drawing two sets, each with n cards from a shuffled deck.
Input Format
The first line contains a comma-seperated string containing the integer seed, which is the seed for
reproducibility, hand, the number of cards to draw per card set, and peek, the number of cards to peek at the
top of the deck. The input follows this format:
<seed>, chand>, <peek>
Constraints
None
Sample Input 0
17,2,4
Sample Output 0
Round 1:
Hand A:
8 of hearts
1 of hearts
Hand B:
7 of spades
Jack of spades
Cards Left: 48
4 Cards at the top:
6 of spades
Queen of clubs
7 of diamonds
9 of hearts
Round 2:
Hand A:
8 of hearts
1 of hearts
6 of spades
Queen of clubs
Hand B:
7 of spades
Jack of spades
7 of diamonds
9 of heartS
Cards Left: 44
Transcribed Image Text:cards_in_deck = ["1 of clubs", "2 of clubs", ... "King of clubs", "1 of spades", "2 of spades", ... "King of spades", "1 of hearts", "2 of hearts", ... "King of hearts", "1 of diamonds", "2 of diamonds", ... "King of diamonds"] The cards inside a deck may also be shuffled. A seed argument is added for reproducibility. The peek method of the class allow you to peek at the top n cards. The default value for nis 5. Lastly, The draw method allows you to draw the top n cards of the deck and transfer these cards to a CardSet instance. The default value of n is 5. Note that the number of cards that you can draw cannot exceed the current number of cards in the deck. In this exercise, you will simulate drawing two sets, each with n cards from a shuffled deck. Input Format The first line contains a comma-seperated string containing the integer seed, which is the seed for reproducibility, hand, the number of cards to draw per card set, and peek, the number of cards to peek at the top of the deck. The input follows this format: <seed>, chand>, <peek> Constraints None Sample Input 0 17,2,4 Sample Output 0 Round 1: Hand A: 8 of hearts 1 of hearts Hand B: 7 of spades Jack of spades Cards Left: 48 4 Cards at the top: 6 of spades Queen of clubs 7 of diamonds 9 of hearts Round 2: Hand A: 8 of hearts 1 of hearts 6 of spades Queen of clubs Hand B: 7 of spades Jack of spades 7 of diamonds 9 of heartS Cards Left: 44
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education