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:
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Step by step
Solved in 4 steps with 2 images