Question: 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 (2 points)
Make sure that cards.py and assignment8.py is in the same directory / folder
In cards.py, define a class with the name Card (2 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 assignment8.py file is using this yet to be defined constructor of the Card class to populate the Card's initial data. (2 points)
Also define a method within the class with the name: get_display_string (2 points)
In the get_display_string 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 10, I want the value to be displayed as "Jack", "Queen", "King", "Ace". That is, an 11 will be displayed as "Jack", 12 as "Queen", 13 as "King", and in a special case 1 will be displayed as "Ace" (since there is no "1" card). Values from 2 to 10 can be displayed as a number. I want the suites to be read in some way other than 1,2,3,4; e.g. Clubs, Spades, Hearts, Diamonds. (2 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...
10 of Hearts
Ace of Diamonds
2 of Clubs
2 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 -8
Diamonds -5
Clubs -9
Diamonds -10
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 4 main categories (eg: clubs, spades, hearts, diamonds) and 13 different values (eg: Ace, 2,3,4,5,6,7,8,9,10, Jack, Queen, King).
Assignment8.py
import random
from cards import Card
def create_deck():
# The deck array-list will contain Cards
deck =[]
# Build the deck, assuming the Card class was imported correctly
for i in range(1,4+1):
for j in range(1,13+1):
deck.append(Card(i,j))
return deck
def main():
print ("The dealer opens a new pack of playing cards.")
my_deck = create_deck()
print ("The dealer shuffles.")
random.shuffle(my_deck)
print ("The dealer pulls five cards from the top.")
print ("And we see...")
for c in my_deck[:5]:
print ('\t'+ c.get_display_string())
if __name__=="__main__":
# execute only if run as a script
main()

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!