Skip to content

Instantly share code, notes, and snippets.

@daniel-schroeder-dev
Created July 18, 2022 22:18
Show Gist options
  • Select an option

  • Save daniel-schroeder-dev/841ff9eaccc7ef7393783a69d77491ca to your computer and use it in GitHub Desktop.

Select an option

Save daniel-schroeder-dev/841ff9eaccc7ef7393783a69d77491ca to your computer and use it in GitHub Desktop.
Twenty-One Roman
"""
################ 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!
-------------------------------------------------------
############################################################
"""
from random import randint
print("Welcome to the game of 21")
max_num = 10
random_number = randint(1,10)
random_num = randint(1,10)
random_numb = randint(1,10)
comp_num = randint(1,10)
comp_number = randint(1,10)
comp_numb = randint(1,10)
total = (random_number + random_num)
comp_total = (comp_num + comp_number)
new_total = (random_number + random_num + random_numb)
new_comp_total = (comp_num + comp_number + comp_numb)
print(f"This is your hand: {random_number} + {random_num}")
print(f"The total of your hand is {total}")
print(f"My hand is: {comp_num} + {comp_number}")
print(f"The total of my hand is {comp_total}")
options = """
hit or stand
(1) hit
(2) stand
"""
print(options)
___ = input("hit or stand ")
# If the user chooses to hit
if ___:
# Draw another card and update the value in `new_total`
# Display the player/dealer's hands
# To bust, you would have more than 21
if new_total <= 22:
print("You got a bust")
elif new_comp_total <= 22:
print("I got a bust")
elif new_total >= new_comp_total:
print("You win!")
elif new_comp_total > new_total:
print("I win!")
elif new_comp_total == new_total:
print("It's a draw!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment