Question: Python: Create a hand of Blackjack Rules Here is an overview of our simplified blackjack rules: Face cards are worth 10 points. Aces are worth

Python: Create a hand of Blackjack

Rules

Here is an overview of our simplified blackjack rules:

Face cards are worth 10 points. Aces are worth either 1 or 11 points, beneficial to the owner of the hand. Other cards are worth their rank value.

The player is dealt two face up cards.

The dealer is dealt a face-down card, and a face-up card.

If both players have 21, the game ends in a tie.

If either player or dealer have 21 and the other doesnt, that player wins the hand.

The player may chose to hit as many times as they wish, or stand.

If a player hits a new card is drawn. If that card makes their total hand value exceed 21, the player busts and loses.

Once a player stands, the dealer reveals their face-down card and may choose to draw. The dealer will always draw at a 16 or lower, and if they go over 21, they bust.

Once both players are done drawing, the highest hand wins.

If the player wins, they double their money. If they lose, they get nothing, and if they tie, they get their wager back.

BlackjackHand

First we will create a class for storing our hand in blackjack, so we can easily figure out how much our hand is worth, or display it to the screen.

__init__()

A BlackjackHand doesnt take in any parameters, but it will need to set up a list for storing Cards.

add_card(new_card)

Adds a card to the hand.

parameters

new_card - the Card object to be added to the hand

__str__()

Returns a string representation of the current hand. The resulting string should contain the __str__() value of each card, delimited by commas.

return

A string representing all the cards in the hand. Example: 7 of Diamonds, King of Spades or Ace of Hearts, 8 of Clubs, Queen of Diamonds

get_value()

Returns a numeric point value of the current hand. This should be the sum of the point values of each card. In our implementation of blackjack, an Ace should be either 11 points, or 1, to give the player the highest score without exceeding 21. Hint: First count the total points assuming all aces are 11, along with the number of aces, then decrement point total as the rules allow.

return

A numeric value representing the value of the hand. Examples, respective to the examples in hand_str, above: 17 or 19.

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!