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 card deck import random
# Deals a card. Values range from to
# This function should get a carddeck as an input and return the carddeck and numeric card value
def dealcardcarddeck:
## create a logic with which you can draw a card from the card deck
# you draw one card from carddeck and assign a numeric card value to cardval variable
cardval random.choicecarddeck
# remove the drawn card from carddeck
carddeck.removecardval
return carddeck, cardval
# Deals the initial two cards for the player and the dealer
carddeck, cardval dealcardcards
# This function should take a carddeck as an input and return the carddeck and scores
def initialdealcarddeck:
# Get the player's score.
carddeck, playerscore dealcardcarddeck
# Get dealer's score.
carddeck, dealerscore dealcardcarddeck
# Get the player's score.
# Get dealer's score.
# Check whether the player or dealer gets two Aces. If so convert their scores to
return carddeck, playerscore, dealerscore
# Handles the player's turn. Returns the point value for the player's hand.
def getscorecarddeck :
carddeck, playerscore, dealerscore initialdealcarddeck
## you should display the sum of the two cards
## then, ask users whether they want to get another card
printThe sum of the first two cards is: playerscore
userresponse inputDo you want to take another card?: YN
## if either the user is busted or the user wants to stop, then you need to stop
while userresponse Y or userresponse y:
# Get the player's and dealer's score.
## Once you got the playerscore, 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 heshe wants to take another card
userresponse inputDo you want to take another card?: YN
## return the player and dealer's score
return playerscore, dealerscore
# Create a card deck from an input file cardstxt
# Then, return cards saved in a list of lists
def setcarddeck:
## 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
userresponse Y
while userresponse Y or userresponse y:
## Set a card deck
cards setcarddeck
# Get scores for the dealer and player.
playerscore, dealerscore getscore cards
## Once you got the playerscore and dealerscore, 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 heshe wants to play another game
userresponse inputDo you want to play another game?: YN
# 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
