Home > other >  My python blackjack game is not working as intended
My python blackjack game is not working as intended

Time:10-25

The problems are:

  1. Upon typing n to stand and winning, it doesnt ask the user again if they want to play a game of blackjack.
  2. And upon winning it also does not ask the user if it wants to play, straight up just starts the game once again.

Please help me solve this, I lost all hope while debugging... p.s. #clear and #art are placeholders

import random

active_game = True  # - Active flag

def restart_game():
    # clear()
    # print(logo)

    cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
    cards_player = [random.choice(cards), random.choice(cards)]
    cards_dealer = [random.choice(cards), random.choice(cards)]


    def total(cards_entity):  # count someone's cards
        return sum(cards_entity)


    print(f"  Your cards: {cards_player}, current score: {total(cards_player)}")
    print(f"  Dealer's first card: {cards_dealer[0]}")

    def final_score():
        print(f"    Your final hand: {cards_player}, final score: {total(cards_player)}")
        print(f"    Dealer's final hand: {cards_dealer}, final score: {total(cards_dealer)}")

    def winner(): #-checks result of move
        if total(cards_player) == 21:       # player got 21
            if total(cards_dealer) == 21:
                print("You both scored a blackjack. It's a draw!            
  • Related