Last active
July 18, 2022 22:27
-
-
Save daniel-schroeder-dev/c6d01c35b3860ea8459292d3647eb433 to your computer and use it in GitHub Desktop.
Twenty-One Kameron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
################ HINTS ##################################### | |
Create an app that simulates a simple game of twenty-one. | |
- You'll need two players. One should be the dealer, the other should be the | |
player (user). | |
- You'll need to generate random numbers, so import the correct function | |
from the correct module. | |
- Assume each round a player can draw a card from 1-10, and simulate two | |
rounds at the beginning of the game so each player has drawn two cards. | |
- So, you should get a random number between 1-20 to simulate drawing two cards. | |
- Display the player's hand after simulating drawing two cards | |
- Ask the user (player) if they want to (1) hit or (2) stand. | |
- If the user (player) hits, simulate drawing another card (from 1-10), display | |
this card, and add the total to the player's current hand. | |
- Print the player and computer's hands | |
- Use conditional statements to determine the winner and display the appropriate | |
message for each possible condition. | |
***** Possible Conditions **************************************************** | |
The player busted (got over 21) | |
- "Player busts, dealer wins!" | |
The player's hand is more than the dealer's hand | |
- "Player wins!" | |
The dealer's hand is more than the players hand | |
- "Dealer wins!" | |
The dealer and the player have the same hand | |
- "It's a draw!" | |
******************************************************************************* | |
Example output (Player wins): | |
------------------------------------------------------- | |
Player's hand: 3 | |
Do you want to (1) hit or (2) stand? 1 | |
Player draws 9 | |
Player's hand: 12 | |
Dealer's hand: 6 | |
Player wins! | |
------------------------------------------------------- | |
Example output (Draw): | |
------------------------------------------------------- | |
Player's hand: 16 | |
Do you want to (1) hit or (2) stand? 2 | |
Player's hand: 16 | |
Dealer's hand: 16 | |
It's a draw! | |
------------------------------------------------------- | |
Example output (Player Busts): | |
------------------------------------------------------- | |
Player's hand: 16 | |
Do you want to (1) hit or (2) stand? 1 | |
Player draws 7 | |
Player's hand: 23 | |
Dealer's hand: 5 | |
Player busts! | |
Dealer wins! | |
------------------------------------------------------- | |
Example output (Player Busts): | |
------------------------------------------------------- | |
Player's hand: 10 | |
Do you want to (1) hit or (2) stand? 1 | |
Player draws 3 | |
Player's hand: 13 | |
Dealer's hand: 16 | |
Dealer wins! | |
------------------------------------------------------- | |
""" | |
# Import something to get random numbers | |
from random import randint | |
def draw_card(): | |
return randint(1, 10) | |
# Track player/dealer hands in variables | |
# Simulate drawing two cards for each player | |
player = draw_card() + draw_card() | |
dealer = draw_card() + draw_card() | |
# Display player/dealer's hands | |
print(f"Player's hand: {player}") | |
print(f"Dealer's hand: {dealer}") | |
# Ask the user which option they want to choose and store it in a variable | |
hit = 1 | |
stand = 2 | |
choose = int(input("Do you want to (1) hit or (2) stand?")) | |
# If the user chose to hit, draw another card and store in `player` | |
if choose == hit: | |
player += # Get a random number from 1 to 10 | |
# Display the final hands of both players | |
print(f"Player's hand = {randit}. Computer's hand = {randit}.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment