<jupyter_start><jupyter_text>Tutorial 2: Part B Blackjack Authors: <NAME>, <NAME>, <NAME> Blackjack is a comparing card game between a player and a dealer. It is played with one or more decks of 52 cards and is one of the most popular casino games.The goal here is to make a simulator for the blackjack game where the computer will act as a dealer and you(or the user) will be the player.  Gameplay Blackjack is based on a scoring system where each card has a value, and the goal is to beat the score of the dealer's hand without going over 21.The value of each card is as follows:   - Number cards (2-10): Their face value (2 has a value of 2, and so on)   - Face Cards(J, Q, K): 10   - Ace: 1 (hard) or 11 (soft) depending on whichever makes a better hand   - Suit is irrelevant.As an example, consider the hand: `2 K A`: If the Ace is given a value of 11, then the total score is 23, which is greater than 21, so it is assigned a value of 1 which gives a score of 13.  Simplified GameplayHere, we describe the simplified gameplay that we will guide you in building in this tutorial.Each player is dealt two cards. One of the dealers cards is hidden from the player. So a possible scenario is                                             Dealer: 9 ?(7)                                            Player: 5 4The player has the following options:***Hit***: ask for another card.***Stand***: hold your total and end your turn.If at any point, the player exceeds 21, then the player loses. After the player ends their turn, the dealer reveals the hidden card. The dealer then hits until the hand The dealer will hit unless his/her cards total 17 or higher after which he must stand.The outcome of the hands is as follows:  - If the player goes over 21 you bust ( i.e. you lose), and the dealer wins regardless of the dealer's hand.  - If you are dealt 21 from the start (Ace & 10), you got a 'blackjack'.      - If both the player and the dealer receive a 'blackjack', no one wins  - If Dealer exceeds 21 and the player does not, the player wins  - If the player attains a final sum higher than the dealer and does not bust, the player wins. For the complete set of rules, have a look this YouTube video.<jupyter_code>from IPython.display import YouTubeVideo
YouTubeVideo('VB-6MvXvsKo')<jupyter_output><empty_output><jupyter_text>---Let us implement this game by first making a minimal version of blackjack and then adding features (similar to `Fraction` in Part A of this tutorial) First, we define the cards. For now, we will not consider suits (since they are irrelevant to the game anyways). Create Python objects (*you decide which kind*) to store the ranks (2-10, J, Q, K, A) and their values.<jupyter_code># When you feel like you need any library, add the imports at the top


# Create global variables for cards, scores of each card. Ignore the suits for now<jupyter_output><empty_output><jupyter_text>---Now, create a shuffled deck of cards. Remember that each deck has cards of 4 suits (52 cards in total)<jupyter_code># Shuffled deck of cards that we will use<jupyter_output><empty_output><jupyter_text>---Next up, write a function that will accept a list of cards (a `hand`) and return the value of the hand. Remember that aces can have two values!<jupyter_code>def calc_score(hand):
    """Return the score of a hand
    
    Aces can take value 11 or 1.
    Numbered cards take the value of their numbers
    Face cards are all valued 10
    """
    pass<jupyter_output><empty_output><jupyter_text>---Now we are ready to get started on the actual gameplay.Deal cards to the player and the dealer. Print out the first card dealt to the dealer and the two cards dealt to the player.For now, simply compare the values of the hands dealt to both parties and decide the winner (which is a boring game, but a game nonetheless)<jupyter_code># Deal 2 cards each to the dealer and the player

# Whoever has the hand with a larger score wins<jupyter_output><empty_output><jupyter_text>---By now you have a completely working game. It's not exactly Blackjack, but it's close! (somewhat).Let's spice things up a bit now: Ask the player if they want to hit or stand (ignore all the other possible options for now), and print the hand that the player has. If they bust, then GAME OVER! If they don't they get to choose again. Repeat this until either the player busts or they decide they have a good enough hand to continue.To summarize, we now have a game where the dealer is dealt two cards, one hidden from the player. The player is dealt two cards and asked if they want to hit or stand, and are allowed to do so until they either stand or bust. Then the person with the higher score among the dealer and the player (if they haven't busted) wins!<jupyter_code># You may find an infinite `while` loop (with a `break` somewhere) to be useful here<jupyter_output><empty_output><jupyter_text>---Now, we implement the dealer's behaviour. After the player is done, the dealer's card is revealed to the player. The dealer must hit if the value is less than 17, and keep going until the value is greater than 17. The moment this happens they must stop. * If the player had gone bust, the dealer wins, even if the dealer goes bust (This is why you shouldn't gamble, kids). * If the dealer goes bust, and the player doesn't, the player wins.* If the dealer and player both don't go bust, the one with the higher score wins!<jupyter_code># You may find `while` loops to be useful here as well.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.05730866884294523, 'fraction_numerical': 0.01051867972433805, 'mean_word_length': 3.859030837004405, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '511295', 'license': 'MIT', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1417, 'n_words': 905, 'path': 'tutorial2/Tutorial2_PartB_unsolved.ipynb', 'repo_name': 'senthil2405/Python-Material', 'size': '5543'}