Implementing the Basic Blackjack Game using Python
Description
Unformatted Attachment Preview
Heejun was dealt a hand with a value of 11
Would you like to take another card? (Y/N) Y
Heejun was dealt a hand with a value of 14
Would you like to take another card? (Y/N) Y
Dealer BUSTED with a total value of 23!
You have stopped taking more cards with a hand value of 15.
** Heejun, You win! **
Would you like to play again? (Y/N) Y
What’s your name?: Heejun
Heejun was dealt a hand with a value of 18
Would you like to take another card? (Y/N) N
You have stopped taking more cards with a hand value of 18.
The dealer was dealt a hand with a value of 10
** Heejun, You win! **
Would you like to play again? (Y/N) Y
What’s your name?: Heejun
Heejun was dealt a hand with a value of 20
Would you like to take another card? (Y/N) N
You have stopped taking more cards with a hand value of 20.
The dealer was dealt a hand with a value of 11
** Heejun, You win! **
Would you like to play again? (Y/N) Y
What’s your name?: Heejun
Heejun was dealt a hand with a value of 11
Would you like to take another card? (Y/N) Y
Heejun was dealt a hand with a value of 12
Would you like to take another card? (Y/N) Y
You BUSTED with a total value of 22!
You have stopped taking more cards with a hand value of 22.
**Heejun, You lose. **?”””You should not share this solution with anyone.
Please remember that you signed an Academic Honesty Agreement.”””
import random
class PlayingCard:
def __init__(self, suit, value):
self.suit = suit
self.value = value
def get_suit(self):
return self.suit
def get_value(self):
return self.value
def get_num_value(self):
if self.value == “ace”:
return 1
elif self.value == “jack”:
return 10
elif self.value == “queen”:
return 10
elif self.value == “king”:
return 10
else:
return self.value
class Deck:
def __init__(self):
self.cards = []
def draw_card(self):
selected_card = random.choice(self.cards)
self.cards.remove(selected_card)
return selected_card
def init_deck(self):
suits = [“hearts”, “diamonds”, “spades”, “clubs”]
values = [“ace”, 2, 3, 4, 5, 6, 7, 8, 9, 10, “jack”, “queen”, “king”]
for suit in suits:
for value in values:
self.cards.append(PlayingCard(suit, value))
class Person:
def __init__(self, deck):
“””set hand and get two initial cards from the deck”””
self.hand = Hand()
self.hand.get_cards(deck)
def play_turn(self, deck):
“””add a card from the deck to hand”””
def report_score(self):
“””report total values of the hand”””
class Dealer(Person):
def __init__(self, deck):
“””inheirt Person Class and set self.name as ‘Dealer'”””
super().__init__(deck)
self.name = “Dealer”
class Player(Person):
def __init__(self, deck, name):
“””inheirt Person Class and set self.name as what a user typed in”””
super().__init__(deck)
self.name = name
class Hand:
def __init__(self):
“””set self.cards as an empty list”””
self.cards = []
def get_cards(self, deck):
“””draw two initial cards from the deck and append them to self.cards”””
self.cards.append(deck.draw_card())
self.cards.append(deck.draw_card())
def get_total_value(self):
“””get total value of cards in the hand”””
## iterate over self.cards and get the total value from self.cards and return it
sum = 0
for card in self.cards:
sum += card.get_num_value()
return sum
def add_card(self, deck):
“””draw one card from the deck and append them to self.cards”””
class BlackjackGame:
def __init__(self):
“””initialize deck and player”””
self.deck = Deck()
self.player = None
self.dealer = None
def play_game(self):
# Prime the loop and start the first game.
user_response = “Y”
while user_response == “Y” or user_response == “y”:
## fill the deck with 52 cards
self.deck.init_deck()
## initialize a player amd dealer and get two cards per player
player_name = input(“What’s your name?: “)
self.player = Player(self.deck, player_name)
self.dealer = Dealer(self.deck)
“””All control should take a place here”””
game = BlackjackGame()
game.play_game()
Purchase answer to see full
attachment
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."