CAPSTONE PROJECT - 1
Blackjack Game
Initialize deck of cards:
Define list cards = [11][2][3][4][5][6][7][8][9][10][10][10][10]
Define a function lost(i):
Display user’s cards up to index i+3, their current total
Display computer’s first card and score
Announce that the player lost
End program
Create two empty lists for hands:
your_card = []
computer_card = []
Deal initial cards:
Randomly add 4 cards to the player’s list
Randomly add 4 cards to the computer’s list
Start the main game loop:
Ask the user if they want to play Blackjack (type ‘y’ or ‘n’)
If user chooses ‘y’:
Display player’s first two cards and current score
Show computer’s first card
Start a nested loop for taking hits:
Ask user: “Type ‘y’ to get another card, or ‘n’ to pass”
If input is ‘y’:
Add a new card and display current cards and total
If total of player’s cards > 21, call the lost() function
If computer’s total > 21 and player < 21, player wins
If both totals are equal, it’s a draw
If player’s total > 21 and computer < 21, player loses
If input is ‘n’:
Display final hands and scores for both player and computer
If computer’s total > 21 and player < 21, or player’s total < computer’s total → player wins
If computer’s total < 21 but player’s total > 21 or player’s total < computer’s → player loses
If scores are equal → draw
End program
If user chooses ‘n’ initially, exit the game.
End of program
Blackjack Game Rules (as applied)
The deck is unlimited in size.
No jokers are used.
Jack, Queen, King = 10 points.
Ace counts as 11 or 1 (simplified here as 11).
Cards have equal draw probability.
Computer acts as the dealer.
Top comments (0)