Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a new file named cards.py ( 2 points ) Make sure that cards.py and assignment 8 . py is in the same directory /
Create a new file named cards.py points
Make sure that cards.py and assignmentpy is in the same directory folder
In cards.py define a class with the name Card points
Be sure to give it a constructor, it should take in two extra arguments, one for the suite of the card and another for the card's value numerical The assignmentpy file is using this yet to be defined constructor of the Card class to populate the Card's initial data. points
Also define a method within the class with the name: getdisplaystring points
In the getdisplaystring method, return a string value that will be used to display what Card this is in an easy to read format. As the user, I want to see what suite the card is and if the card's value is over I want the value to be displayed as "Jack", "Queen", "King", "Ace". That is an will be displayed as "Jack", as "Queen", as "King", and in a special case will be displayed as "Ace" since there is no card Values from to can be displayed as a number. I want the suites to be read in some way other than ; eg Clubs, Spades, Hearts, Diamonds. points
When I run the program with your cards.py file, I would be happy if I saw the following results:
The dealer opens a new pack of playing cards.
The dealer shuffles.
The dealer pulls five cards from the top.
And we see...
of Hearts
Ace of Diamonds
of Clubs
of Spades
King of Spades
Here' s another example:
The dealer opens a new pack of playing cards.
The dealer shuffles.
The dealer pulls five cards from the top.
And we see...
Diamonds
Diamonds
Clubs
Diamonds
Diamonds Jack
The string representation of your card can be different. I only ask that it is somewhat related to a normal pack of cards where there are main categories eg: clubs, spades, hearts, diamonds and different values eg: Ace, Jack, Queen, King
Assignmentpy
import random
from cards import Card
def createdeck:
# The deck arraylist will contain Cards
deck
# Build the deck, assuming the Card class was imported correctly
for i in range:
for j in range:
deck.appendCardij
return deck
def main:
print The dealer opens a new pack of playing cards."
mydeck createdeck
print The dealer shuffles."
random.shufflemydeck
print The dealer pulls five cards from the top."
print And we see..."
for c in mydeck::
print t cgetdisplaystring
if namemain:
# execute only if run as a script
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started