![]() For this third section, you should do the following: You then need to implement the third section marked with # THIRD SECTION INSERT YOUR CODE HERE. After each card is drawn, the player’s hand needs to be checked to see whether they have won, they are bust, or whether everything is okay.You will need to implement display_player(player) and display_dealer(opponent, start=true) after each draw. You need to implement the part where the user provides an h, which stands for ‘hit’ (that is, for drawing a card), and s, which stands for ‘stay’ (that is, to stop drawing cards). If the user action is q, then the game quits. The code has already been provided that prompts the user for an action and stores this in player_action. For this second section, you should do the following: You then need to implement the second section marked with # SECOND SECTION INSERT YOUR CODE HERE. These functions have been written already, but will need to be placed correctly. The cards will be displayed using the display_player(player) function and the display_dealer(opponent, start=true) function. Create two variables, one for each player, that stores the count of the player’s hands.Draw two cards for each player and add them to the respective player’s hands.Create a new deck of cards using the create_standard_deck() function.Create a list for the player called ‘player’, which will hold the cards in the player’s hand, and then create another list for the dealer called ‘dealer’, which will hold the cards in the dealer’s hand.For this first section, you should do the following: In the first part of this task, you will implement the section marked with # FIRST SECTION INSERT YOUR CODE HERE. ![]() Your task is to now combine everything together to create the blackjack game that is defined in the create_blackjack_game(user_input) function. Implement the check_cards() function to check if the player has won, lost, or has room to hit. If they have a count that is greater than 21, then it returns ‘BUST’ otherwise, it returns ‘OK’. The function takes a player’s hand as input and returns ‘WIN’ if the input player has exactly a count of 21. Your task is to complete the function stub check_cards(player). Task Implement the `get_count` function to calculate the value of cards in a player's hand. Finally, for the purposes of this implementation, we will only treat the Ace with a value of 11. You need to ensure that the Jack, Queen, and King cards all have a value of 10. Currently, in the deck, Jack has a value of 11, Queen has a value of 12, King has a value of 13, and Ace has a value of 14. It should be noted that a special mapping is required. The function calculates and returns the value of the player’s hand. ![]() The function takes a player’s hand, which is a list, as input. Your task is to complete the function stub get_count(player). Getting the Count of the Cards in a Player’s Hands Implement the draw_card() function which deals cards to the dealer and players and removes the corresponding card from the deck. Once this is done, the function needs to return the card that was selected. The function should randomly select a card from the deck using the random.choice() method and then remove the card from the deck by completing the remove_card_from_the_deck() function. Your task is to complete the function stub draw_card(deck). Implement the create_deck() function to create the deck of cards. This entire implementation can be done neatly in about eight functions. For example, a function to check the score of a player’s hand, to check whether a player has won, and so on. It’s worth breaking up each functional task in create_blackjack_game() into separate functions. If at any time the dealer’s total value is above 21, then the dealer busts and the player wins.įinally, if both the player and dealer scores are below 21, and no one has busted yet, the player with the highest total wins. If it is greater than or equal to 17 but less than or equal to 21, then the dealer must stay. If the total value in the dealer’s hand is less than 17, then they must hit. If the player stays, then it’s the dealer’s turn to act. Display each updated hand after each card draw. If it is, then the player wins, and if it is above 21, then the player loses. If the player hits, keep checking whether the total value of the player’s cards is equal to 21. Prompt the player to either hit (that is, draw another card) or stay. Give each player two cards (chosen randomly using random.choice). The game logic needs to follow this pattern: To get you warmed up, they want you to be able to create a blackjack game simulator. You’ve just been hired by a small-town casino that wants to create a simulated card playing platform. Note: So far none of the posted answers have worked for me Python Module Lab Assessment 5: Creating a Blackjack Simulator
0 Comments
Leave a Reply. |