#๐Ÿ”’ Help with blackjack game

20 messages ยท Page 1 of 1 (latest)

drifting tokenBOT
#

@wary kiln

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wary kiln
#
import random

face_values = ["T", "J", "Q", "K", "A"]
player_cards = []
player_value = 0
dealer_cards = []
dealer_value = 0
deck = []

for rank in ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']:
    for suit in "โ™ โ™ฅโ™ฆโ™ฃ":
        card = (rank, suit)
        deck.append(card)

def deal_card():
    return deck.pop()

def card_value(person):
    total = 0
    if person == player_cards:
        for card in person:
            if card[0] in face_values:
                total += 10
            else:
                total += int(card[0])
    elif person == dealer_cards:
        for card in person:
            if card[0] in face_values:
                total += 10
            else:
                total += int(card[0])
    else:
        if dealer_cards[1][0] in face_values:
            total += 10
        else:
            total += int(dealer_cards[1][0])       

    return total

def display_cards(situation):
    if situation == "finish":
        print("\nYour cards: {} {}  \nMy Cards:   {}  {}\n".format(card_value(player_cards), player_cards, card_value(dealer_cards), dealer_cards))
    else:
        print("\nYour cards:      {} {}  \nMy visible card: {} [{}]\n".format(card_value(player_cards), player_cards, card_value("hidden"), dealer_cards[1]))

def dealer_turn():
    pass

def start_of_game():
    random.shuffle(deck)

    for i in range(2):
        player_cards.append(deal_card())
        dealer_cards.append(deal_card())

    player_value = card_value(player_cards)
    dealer_value = card_value(dealer_cards)

    print("I have dealt both of us two cards.")
    display_cards(0)

    while player_value < 21 and dealer_value < 21:
#
        choice = input("Would you like to (hit) or (stand): ")
        if choice == "hit":
            player_cards.append(deal_card())
            player_value = card_value(player_cards)
            display_cards(0)
        if choice == "stand":
            dealer_turn()
            display_cards("finish")
#

this is my current code

#

id like to implement the rest of the blackjack rules

#

howerver currently i feel like the function start_of_game

#

is a bit unoptimized for adding more features

balmy prism
#

Instead of "aaa" you should put your question there instead.

#

If your code is too long to paste in one Discord message paste it to the pastebin

#

!paste

drifting tokenBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

wary kiln
#

okay sorry mate

#

anyways

#
    if player_value > 21:
        print("You Lose!")
        return 0
    
    while dealer_value <= 16:
        dealer_cards.append(deal_card())
        display_cards(0)
        time.sleep(3)
#

so ive implemented this

#

now after the player busts, id like to exit out of the function "start_of_game"

#

is return 0 the best way to do it?

drifting tokenBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ Help with blackjack game