Card
Create a class called Card
in a file called card.py
that represents a playing card. The class does not need to represent joker cards. The class should contain the following methods:
An __init__
method that takes two integers, one that represents the suit and one that represents the rank of a card.
A __str__
method that returns a string that represents the card.
A method called value
that returns an int that represents the value of the card. The Ace has the value 11. The face cards, Jack, Queen, and King, have the value 10. All other cards have the value of their rank.
Create a program that imports the card module to test the class and its methods.
Deck
Create a class called Deck
in a file called deck.py
that represents a deck of playing cards. The class should contain the following methods:
An __init__
method that has no parameters and fills the deck with one of every card, in a random order. Each card should be an object of the Card
class.
A __str__
method that returns a string that represents the deck.
A method called remove_top
that removes and returns the card on the top of the deck.
Create a program that imports the deck module to test the class and its methods.
Hand
Create a class called Hand
in a file called hand.py
that represents a hand of playing cards. The class should contain the following methods:
An __init__
method that has no parameters and initializes a hand with no cards.
A method called add_card
that takes a Card
object and adds it to the hand.
A __str__
method that returns a string that represents the hand.
A method called total_value
that returns the total value of all of the cards in the hand.
Create a program that imports the hand module to test the class and its methods.
Black Jack
Create a program in a file called black_jack.py
that plays a single hand of black jack. The program should:
create a deck of cards and two hands, one for the dealer and one for the player.
deal two cards from the deck into the hand of the dealer and two cards into the hand of the player.
repeatedly print the user’s hand and prompt the user to hit or stay. If the user enters “hit”, a card should be dealt from the deck to the players hand and the new hand printed. If the player enters anything but “hit”, the loop should stop.
repeatedly print the dealer’s hand and deal a card from the deck to the dealer’s hand until the dealer’s hand has a total value of 17 or more.
print who won. The winner is whoever gets closest to 21 without going over. If both the player and the dealer go over 21 or if they have the same total value then it is a tie.
Submission
Submit a zip file of your code on the course Inquire site that uses your last names as the file name.