Blackjack is a card game sometimes called Twenty-One. The object of Blackjack is to have a hand of cards whose score is 21, or as close to this as possible. A player whose hand exceeds a score of 21 is said to have bust and loses. A hand in Blackjack is scored as follows: • Cards 2 to 10 are given their card value as points (i.e. 2 to 10 points). • Face cards, the Jack, Queen and King, are all worth 10 points. • The Ace card is worth 11 points, or 1 point if doing so prevents the player from going bust. For example, if a player's hand has three Aces and a 6, one of the Aces will be worth 11 points, while the other two will be worth 1 point, making the score for the hand 19 (11 + 1 + 1 + 6). If all three Aces are worth 11, then the score for the hand would be 39 (11 + 11 + 11 + 6) and the player would be bust. Similarly, if two of the Aces are worth 11 points, then the score of the hand would be 29 (11 + 11 + 1 + 6) and the player would also be bust. Complete the blackjack_hand_score() function that takes a single list of strings as parameter called hand and calculates its score. The cards in a hand are represented as strings:

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
icon
Concept explainers
Question
Blackjack is a card game sometimes called Twenty-One. The object of
Blackjack is to have a hand of cards whose score is 21, or as close to this as
possible. A player whose hand exceeds a score of 21 is said to have bust and
loses. A hand in Blackjack is scored as follows:
• Cards 2 to 10 are given their card value as points (i.e. 2 to 10 points).
• Face cards, the Jack, Queen and King, are all worth 10 points.
• The Ace card is worth 11 points, or 1 point if doing so prevents the
player from going bust. For example, if a player's hand has three Aces
and a 6, one of the Aces will be worth 11 points, while the other two will be
worth 1 point, making the score for the hand 19 (11 + 1 + 1 + 6). If all three
Aces are worth 11, then the score for the hand would be 39 (11 + 11 + 11 +
6) and the player would be bust. Similarly, if two of the Aces are worth 11
points, then the score of the hand would be 29 (11 + 11 + 1 + 6) and the
player would also be bust.
Complete the blackjack_hand_score() function that takes a single
list of strings as parameter called hand and calculates its score. The cards
in a hand are represented as strings:
• Cards 2 to 10 are represented as "2", "3", ...,
"10".
• Face cards, the Jack, Queen and King, are represented as "J", "Q" and
"K".
• The Ace card is represented as "A".
Some examples of the function being called are shown below.
Transcribed Image Text:Blackjack is a card game sometimes called Twenty-One. The object of Blackjack is to have a hand of cards whose score is 21, or as close to this as possible. A player whose hand exceeds a score of 21 is said to have bust and loses. A hand in Blackjack is scored as follows: • Cards 2 to 10 are given their card value as points (i.e. 2 to 10 points). • Face cards, the Jack, Queen and King, are all worth 10 points. • The Ace card is worth 11 points, or 1 point if doing so prevents the player from going bust. For example, if a player's hand has three Aces and a 6, one of the Aces will be worth 11 points, while the other two will be worth 1 point, making the score for the hand 19 (11 + 1 + 1 + 6). If all three Aces are worth 11, then the score for the hand would be 39 (11 + 11 + 11 + 6) and the player would be bust. Similarly, if two of the Aces are worth 11 points, then the score of the hand would be 29 (11 + 11 + 1 + 6) and the player would also be bust. Complete the blackjack_hand_score() function that takes a single list of strings as parameter called hand and calculates its score. The cards in a hand are represented as strings: • Cards 2 to 10 are represented as "2", "3", ..., "10". • Face cards, the Jack, Queen and King, are represented as "J", "Q" and "K". • The Ace card is represented as "A". Some examples of the function being called are shown below.
For example:
Test
hand = ["A", "K"]
print("Hand: ", hand, "hand score:", blackjack_hand_score (hand))
hand = ["A", "J", "A"]
print("Hand:", hand, "hand score:", blackjack_hand_score (hand))
hand =
["9", "8", "7"]
print("Hand:", hand, "hand score:", blackjack_hand_score (hand))
Transcribed Image Text:For example: Test hand = ["A", "K"] print("Hand: ", hand, "hand score:", blackjack_hand_score (hand)) hand = ["A", "J", "A"] print("Hand:", hand, "hand score:", blackjack_hand_score (hand)) hand = ["9", "8", "7"] print("Hand:", hand, "hand score:", blackjack_hand_score (hand))
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning