Do not import any modules other than the random module which is needed to deal cards. • A submission that uses python dictionaries will not be accepted. • Your program must run one “main()” function which calls all other functions, and must run without run time errors. • Include professional looking output which means: The output has meaningful headers and information for the user. Inputs have self-explanatory prompts, specifying a sentinel, if necessary. There is appropriate bordering and spacing between both information outputs like headers and footers, and data prompts and outputs. Bordering means using a line of symbols such as “###” or “+++” to separate sections of output so that users can easily see what output belongs together and separate. In this project you will build some components of a program that would be used in a game of Blackjack. You will not build an entirely functional Blackjack game. Below are some general rules to give you an overall orientation of how Blackjack is played. You must assume that the user (the player) does not understand the game, so include the below sentence at the beginning of the program after the assignment header, formatted similar to your other headers: • Use this sentence: “The objective in Blackjack is to have a hand with a total value higher than the dealer’s without going over 21. Aces are worth 11, Kings, Queens, Jacks and Tens are worth a value of 10, and the remaining cards are counted at face value.” • * Note that in the actual game, a player may decide if an Ace has the value of 1 or 11, but your program will include a simplifying assumption described later. Overview of the Game (assume only one player and the dealer): • Dealer and player are dealt initial cards. One for the dealer and two for the player. The value of the hand is the sum of the numeric values of the cards in the hand. • The player sees the dealer’s initial card, which will not change until after the player has finished “playing” his hand. • To play her hand, the player can either 1) get “Blackjack” and win if the initial hand is worth 21, 2) go “bust” and lose if the hand goes over 21, or 3) “stand” with a hand total of less than or equal to 21. • If the player does not get “Blackjack,” then she “plays” her hand, deciding whether to “stand” and take no more cards, or be “hit” and get additional cards, one at a time, where she must stand or hit after each card is dealt. This continues until 1) she decides to stand on the total if it is 21 or under, or 2) goes “bust” and loses the game if the hand is over 21. • After the player is finished, then the dealer plays his hand. • The dealer’s play is identical except that dealer must draw another card if his hand is less than 17. So, the dealer can either 1) go “bust” and lose with a hand over 21, or 2) “stand” with a hand total of 17 to 21. • Finally, the winner is declared. If the player hits Blackjack or the dealer goes bust then the player wins. If the player goes bust, then the dealer wins. If neither of these occur, then the person with the highest hand wins. If the dealer’s and player’s hands are equal, then the game is a tie. The Assignment Program This overall program must include these 5 high-level functions. • main, the assignment header, program 1, program 2, and an assignment footer. Programs 1 & 2 will have additional functions for them to run: The definition of your main should be the first program listed at the top of your code, and main is called at the very bottom of your code, after all of the functions have been defined. Program 1: “Determining the Winner” Assume the play has already finished. The user will input the final status of the game, and the program prints out who won. I will input various final statuses to see if your output is correct. The information typed in by the user must include:
Here's a Python program that implements the requirements you've outlined for a simplified version of Blackjack. The program consists of two main parts: determining the winner and simulating the dealer's play. Each part is encapsulated in its own set of functions, and the program is structured to provide clear output and user prompts.
import random
def main():
print_header()
dealer_result = dealer_play()
player_result = get_player_result()
print(determine_winner(dealer_result, player_result))
print("Program finished.")
def print_header():
print("###" * 10)
print("### Welcome to the Blackjack Game ###")
print("###" * 10)
print("The objective in Blackjack is to have a hand with a total value higher than the dealer’s without going over 21.")
print("Aces are worth 11, Kings, Queens, Jacks and Tens are worth a value of 10, and the remaining cards are counted at face value.")
print("###" * 10)
def dealer_play():
initial_card = get_dealer_initial_card()
dealer_hand = [initial_card]
dealer_value = initial_card
print(f"Dealer is dealt a {initial_card} giving a hand value of {dealer_value} and status is hit.")
while dealer_value < 17:
new_card = deal_card()
dealer_hand.append(new_card)
dealer_value += new_card
if dealer_value > 21:
print(f"Dealer is dealt a {new_card} giving a hand value of {dealer_value} and status is bust.")
return ["bust", dealer_value]
else:
print(f"Dealer is dealt a {new_card} giving a hand value of {dealer_value} and status is hit.")
print(f"Dealer stands with a hand value of {dealer_value}.")
return ["stand", dealer_value]
def get_dealer_initial_card():
card = int(input("Enter the dealer’s initial face card (2-10, 10 for J/Q/K): "))
if card > 10 or card < 2:
print("Invalid card value. Please enter a value between 2 and 10 (10 for J/Q/K).")
return get_dealer_initial_card()
return card
def deal_card():
return random.randint(2, 10) # Simulating card values from 2 to 10
def get_player_result():
player_blackjack = input("Did the player hit Blackjack? (yes/no): ").strip().lower() == 'yes'
player_bust = input("Did the player go bust? (yes/no): ").strip().lower() == 'yes'
player_hand_value = int(input("Enter the player's hand value: "))
return [player_blackjack, player_bust, player_hand_value]
def determine_winner(dealer_result, player_result):
dealer_status, dealer_value = dealer_result
player_blackjack, player_bust, player_value = player_result
if player_blackjack:
return "Player wins with Blackjack!"
if player_bust:
return f"Dealer wins! Player status is bust with a hand value of {player_value}."
if dealer_status == "bust":
return f"Player wins! Dealer status is bust with a hand value of {dealer_value}."
if player_value > dealer_value:
return f"Player wins! Player status is stand with a hand value of {player_value}.\nDealer status is stand with a hand value of {dealer_value}."
elif player_value < dealer_value:
return f"Dealer wins! Player status is stand with a hand value of {player_value}.\nDealer status is stand with a hand value of {dealer_value}."
else:
return f"It's a tie! Both have a hand value of {player_value}."
if __name__ == "__main__":
main()
The program includes clear prompts and outputs, with appropriate spacing and headers to enhance readability. The results are presented in a professional manner, making it easy for users to understand the outcome of the game.