Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Can I have the answer to this question by using Python ? Overview: Blackjack, also know as twenty-one, is a card game that is

Hello,

Can I have the answer to this question by using Python?

Overview:

Blackjack, also know as twenty-one, is a card game that is played at casinos around the world. In casinos, players bet money on each hand (with, as you would expect in a casino, the odds stacked in favor of the dealer). Point-based variants of the game are also popular, including a large number of Blackjack Phone Apps for Andriod and iPhone.

In this assignment we'll be developing a simplified version of Blackjack. Our version will proceed as follows:

At the start of a new hand, the player will be dealt two cards. The player will then choose, with a goal of obtaining a set of cards that sum as close to 21 as possible without going over, to either "HIT" (get an additional card to add to the player's hand) or "STAY" (stick with the player's existing hand of cards). If the sum of the values of all cards in a player's hand ever goes over 21, they player immediately loses the hand. We call this way of losing "going bust." If the player chooses to STAY before going bust (i.e., with a hand value of 21 or less), it becomes the dealer's turn.

For our game, the dealer is the computer. In the Basic Requirements, you should assign the computerized dealer a score at random within in the range 16-21. We'll look at a more sophisticated approach in the Advanced Requirements below. This computerized dealer score will then be compared to the player's total hand value. If the computer's score is greater than or equal to the player's total hand value (and not over 21), then the player loses the hand. Otherwise, the player wins!

The deck of cards: Traditionally, a deck of playing cards contains 52 cards, with 13 different card values (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King), each of which is found in four distinct suits (Hearts, Diamonds, Spades, and Clubs). In this assignment, we'll ignore suits. For the Basic Requirements, we'll further simplify things to use a deck of cards that has the values from 1 through 10. Moreover, we'll ignore the fact that when playing with real cards, each card can only be used once in a given hand. These assumptions let us simplify the process of dealing a card to the generation of a random number in the range of 1 to 10. For this assignment's Advanced Requirements, we'll add some of this complexity back into the program.

Basic Requirements:

You are to implement the basic blackjack game as outlined above. It should provide clear prompts and displays to the user along they way. These prompts should be clear enough to tell the user all they need to play the game, and to determine who wins each hand. The basic flow of the game should be as follows:

Deal two cards to the user, compute the sum, and display it to the user. (Remember, a card is just a random number form 1 to 10).

Ask the user if he/she wishes to HIT or STAY.

Each time the user chooses to HIT, deal him/her a new card, update the total, and check to see if he/she has gone bust (over the limit of 21).

Eventually, the player will choose to stay or go bust. If the player goes bust, he/she automatically loses. If not, then the computer gets its turn.

Generate the computer's score and compare it to the player's score and determine who wins. The computer's score should be a random number between 16 and 21.

Ask the user if he or she is ready to play a new hand of blackjack. If so, your program should go to back to step 1. If not, your program should quit.

Developing the solution for this program would be quite challenging without using functions. To make your job easier, think about how functions can be used to simplify the design. Your solution should have, at a minimum, the following functions:

main: the main function, which should have the main loop that repeats for each hand

get_player_score: handles the initial deal of two cards to the player and the "HIT or STAY" loop. It should return the final player score.

deal_card: generate a card value for the player (using random). This should be used within the get_player_score function. The value should be between 1 and 10.

get_dealer_score: generate the dealer's score (using random)

You may find that additional functions are useful to modularize your design. Adding more functions when appropriate is perfectly fine! However, the four functions identified above are REQUIRED.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions