Question: How do I complete this code using 5 2 card deck import random # Deals a card. Values range from 1 to 1 1 #

How do I complete this code using 52 card deck import random
# Deals a card. Values range from 1 to 11
# This function should get a card_deck as an input and return the card_deck and numeric card value
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 a numeric card value to card_val variable
card_val = random.choice(card_deck)
# remove the drawn card from card_deck
card_deck.remove(card_val)
return card_deck, card_val
# Deals the initial two cards for the player and the dealer
card_deck, card_val = deal_card(cards)
# This function should take a card_deck as an input and return the card_deck and scores
def initial_deal(card_deck):
# Get the player's score.
card_deck, player_score = deal_card(card_deck)
# Get dealer's score.
card_deck, dealer_score = deal_card(card_deck)
# Get the player's score.
# Get dealer's score.
# Check whether the player or dealer gets two Aces. If so, convert their scores to 12
return card_deck, player_score, dealer_score
# Handles the player's turn. Returns the point value for the player's hand.
def get_score(card_deck ):
card_deck, player_score, dealer_score = initial_deal(card_deck)
## you should display the sum of the two cards
## then, ask users whether they want to get another card
print("The sum of the first two cards is:", player_score)
user_response = input("Do you want to take another card?: (Y/N)")
## 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 and dealer's score.
## Once you got the player_score, you have to check whether the player got busted and whether whether dealer got busted.
## If one of them got busted, return their scores immediately.
## 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 and dealer's score
return player_score, dealer_score
# 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.
# This while loop controls whether the player wants to play another game or not
user_response ="Y"
while user_response =="Y" or user_response =="y":
## Set a card deck
cards = set_card_deck()
# Get scores for the dealer and player.
player_score, dealer_score = get_score( cards )
## Once you got the player_score and dealer_score, you have to check whether the player got busted, whether player's score
## is larger than the dealer's score. you also need to check the dealer's score.
## According to the result you should diaply different prompt.
## 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()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!