This python... I have provided the cards.txt and the skeleton for the code. Please may someone answer with the right cod

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

This python... I have provided the cards.txt and the skeleton for the code. Please may someone answer with the right cod

Post by answerhappygod »

This python... I have provided the cards.txt and the skeletonfor the code. Please may someone answer with the right code becausesomeone else previously put random things?
This Python I Have Provided The Cards Txt And The Skeleton For The Code Please May Someone Answer With The Right Cod 1
This Python I Have Provided The Cards Txt And The Skeleton For The Code Please May Someone Answer With The Right Cod 1 (156.15 KiB) Viewed 23 times
This Python I Have Provided The Cards Txt And The Skeleton For The Code Please May Someone Answer With The Right Cod 2
This Python I Have Provided The Cards Txt And The Skeleton For The Code Please May Someone Answer With The Right Cod 2 (172.09 KiB) Viewed 23 times
This Python I Have Provided The Cards Txt And The Skeleton For The Code Please May Someone Answer With The Right Cod 3
This Python I Have Provided The Cards Txt And The Skeleton For The Code Please May Someone Answer With The Right Cod 3 (55.89 KiB) Viewed 23 times
For this assignment, you will keep working on developing a simplified version of the Blackjack game. Please refer to the assignment 4 instruction for more details about the Blackjack game. There are two major differences from the previous assignment. Input Data: In the previous assignment, you created cards from a random number generator. Now, you will create conventional 52 cards by reading a file (cards.txt) and converting information from this file to a list of lists. The following are examples from the file: Ace, Heart Ace, Diamond Ace,Spade Ace,Club 2,Heart 2,Diamond 2,Spade 2,Club Each line consists of a card value and suit. After reading each line, you can use a split() function (covered in Week7, Lists) to split the card value and suit. Then, you need create a list of lists (two-dimensional list). The following is an example of the list of lists: [[Ace,Heart], [Ace, Diamond], [Ace,Spade], [Ace,Club], [2,Heart], [2,Diamond], [2,Spade], [2,Club], ...] This logic should be implemented in the set_card_deck() functions. Value & Suit: Although suits were included, they do not matter in winning or losing. It becomes a little more complicated by considering alphabet values. However, simply they are: • Face cards (J,Q,K) count as 10. • Ace can count as a 1 or an 11 depending on which value helps the hand the most. In this assignment, we will treat Ace as 1. As alphabet cards are strings, you have to add logic to convert these alphabet cards (A,J,Q,K) to numeric values accordingly. This logic should be implemented in the deal_card() function.
import random # Deals a card. Values range from 1 to 10 def deal card (card_deck): ## create a logic with which you can draw a card from the card deck # you draw one card from card_deck and assign it to card_val # remove the drawn from card_deck return card_deck, card_val # Handles the player's turn. Returns the point value for the player's hand. def get_player_score(card_deck ): card_deck, hand_val= deal_card(card_deck) card_deck, temp_val= deal_card(card_deck) hand_val+ temp_val print("The sum of the first two cards is:", hand_val) user_response = input ("Do you want to take another card?: (Y/N)") ## you should display the sum of the two cards ## then, ask users whether they want to get another card ## if either the user is busted or the user wants to stop, then you need to stop while user_response == "y" or user_response == "y": # Get the player's score. busted card_deck, temp_val= deal_card(card_deck) hand val + temp_val ## Once you got the player_score, you have to check whether the player got ## According to the result you should display different prompts. ## ask user whether he/she wants to take another card user_response = input ("Do you want to take another card?: (Y/N)") ## return the player's score return hand_val # Handle's the dealer's turn. Returns the point value for the player's hand. def get_dealer_score(): # Deals a card. Values range from 16 to 21
hand_val= random.randint (16, 21) return hand_val # Create a card deck from an input file (cards.txt). # Then, return 52 cards saved in a list of lists def set_card_deck(): ## Complete this function return cards # The main function. It repeatedly plays games of blackjack until the user decides to stop. def main(): # Prime the loop and start the first game. user_response = "Y" while user_response == "y" or user_response == "y": ## Set a card deck cards set_card_deck() # Get the player's score. player_score = get_player_score( cards ) ## Once you got the player_score, you have to check whether the player got busted, whether player's score ## is larger than the dealer's score. According to the result you should display different prompts. ## ask user whether he/she wants to play another game user_response = input ("Do you want to play another game?: (Y/N)")
# The main function. It repeatedly plays games of blackjack until the user decides to stop. def main(): # Prime the loop and start the first game. user_response = "Y" while user_response == "y" or user_response == "y": ## Set a card deck cards set_card_deck() # Get the player's score. player_score = get_player_score( cards ) ## Once you got the player_score, you have to check whether the player got busted, whether player's score ## is larger than the dealer's score. According to the result you should display different prompts. ## ask user whether he/she wants to play another game user_response = input ("Do you want to play another game?: (Y/N)") # Call the main function to start the blackjack program. main()
Ace, Heart Ace, Diamond Ace, Spade Ace, Club 2, Heart 2, Diamond 2, Spade 2, Club 3, Heart 3, Diamond 3, Spade 3, Club 4, Heart 4, Diamond 4, Spade 4, Club 5, Heart 5, Diamond 5, Spade 5, Club 6, Heart 6, Diamond 6, Spade 6, Club 7, Heart 7, Diamond 7, Spade 7, Club 8, Heart 8, Diamond 8, Spade 8, Club 9, Heart 9, Diamond 9, Spade 9, Club 10, Heart 10, Diamond 10, Spade 10, Club Jack, Heart Jack, Diamond Jack, Spade Jack, Club Queen, Heart Queen, Diamond Queen, Spade Queen, Club King, Heart King, Diamond King, Spade King, Club
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply