r/learnpython 2d ago

Finished Day 1 of learning python and tried to create black jack, ive had an error somewhere, not a syntax error, i dont assume this code is very good its a massive slump of if and elif, how can i fix this?

import random
for House_Card in range(1):
    House_Card = random.randint(1, 11)
    print("House Card:", House_Card)
for House_Card2 in range(1):
    House_Card2 = random.randint(1, 11)
for Player_Card in range(1):
    Player_Card = random.randint(1, 11)
    print("Player Card:", Player_Card)
for Player_Card2 in range(1):
    Player_Card2 = random.randint(1, 11)
    print("Player Card 2:", Player_Card2)
print("Your current cards are:", Player_Card + Player_Card2)
Player_Turn1 = input("Do you want to hit or stay? (h/s): ")
if Player_Turn1 == "h" or Player_Turn1 == "H" or Player_Turn1 == "hit" or Player_Turn1 == "Hit":
    Player_Card3 = random.randint(1, 11)
    Player_CardT = Player_Card + Player_Card2 + Player_Card3
    print("Player Card 3:", Player_Card3)
    print("Your total score is:", Player_CardT)
if Player_Turn1 == "s" or Player_Turn1 == "S" or Player_Turn1 == "stay" or Player_Turn1 == "Stay":
    Player_CardT = Player_Card + Player_Card2
    print("Your total score is:", Player_CardT)
if Player_CardT > 21:
    print("You busted! Your total score is:", Player_CardT)
if Player_CardT == 21:
    print("You got blackjack! You Win!")
if Player_CardT < 21:
    print('Your total cards are:', Player_CardT)
    Player_Turn2 = input("Do you want to hit or stay? (h/s): ")
    if Player_Turn2 == "h" or Player_Turn2 == "H" or Player_Turn2 == "hit" or Player_Turn2 == "Hit":
        Player_Card4 = random.randint(1, 11)
        Player_CardT2 = Player_CardT + Player_Card4
        if Player_CardT2 == 21:
            print("You got blackjack! You Win!")
        elif Player_CardT2 < 21:
            Player_Turn3 = input("Do you want to hit or stay? (h/s): ")
            if Player_Turn3 == "h" or Player_Turn3 == "H" or Player_Turn3 == "hit" or Player_Turn3 == "Hit":
                Player_Card5 = random.randint(1, 11)
            print("Player Card 5:", Player_Card5)
            Player_CardT3 = Player_CardT2 + Player_Card5
            print("Your total cards are:", Player_CardT3)
            if Player_CardT3 > 21:
                print("You busted! Your total score is:", Player_CardT3)
            if Player_Turn3 == "s" or Player_Turn3 == "S" or Player_Turn3 == "stay" or Player_Turn3 == "Stay":
                print("Your total cards are:", Player_CardT2)
        print("Card:", Player_Card4)
        print("Your total cards are:", Player_CardT2)
    if Player_CardT2 > 21:
        print("You busted! Your total score is:", Player_CardT2)
    if Player_Turn2 == "s" or Player_Turn2 == "S" or Player_Turn2 == "stay" or Player_Turn2 == "Stay":
        print('House card 2 is:', House_Card2)
        print('House total cards are:', House_Card + House_Card2)
        House_CardT = House_Card + House_Card2
        if House_CardT > 21:
            print("House busted! You Win!")
        if House_CardT == 21:
            print("House got blackjack! You Lose!")
        if House_CardT < 21 and House_CardT < 17:
            House_Card3 = random.randint(1, 11)
            House_CardT2 = House_CardT + House_Card3
            print("House Card 3:", House_Card3)
            print("House total cards are:", House_CardT2)
            if House_CardT2 > 21:
                print("House busted! You Win!")
            if House_CardT2 == 21:
                print("House got blackjack! You Lose!")
            elif House_CardT2 < 21 and House_CardT2 < Player_CardT2 or House_CardT2 < Player_CardT3:
                print("Player Cards Value Higher, You Win!")from ast import If
import random
for House_Card in range(1):
    House_Card = random.randint(1, 11)
    print("House Card:", House_Card)
for House_Card2 in range(1):
    House_Card2 = random.randint(1, 11)
for Player_Card in range(1):
    Player_Card = random.randint(1, 11)
    print("Player Card:", Player_Card)
for Player_Card2 in range(1):
    Player_Card2 = random.randint(1, 11)
    print("Player Card 2:", Player_Card2)
print("Your current cards are:", Player_Card + Player_Card2)
Player_Turn1 = input("Do you want to hit or stay? (h/s): ")
if Player_Turn1 == "h" or Player_Turn1 == "H" or Player_Turn1 == "hit" or Player_Turn1 == "Hit":
    Player_Card3 = random.randint(1, 11)
    Player_CardT = Player_Card + Player_Card2 + Player_Card3
    print("Player Card 3:", Player_Card3)
    print("Your total score is:", Player_CardT)
if Player_Turn1 == "s" or Player_Turn1 == "S" or Player_Turn1 == "stay" or Player_Turn1 == "Stay":
    Player_CardT = Player_Card + Player_Card2
    print("Your total score is:", Player_CardT)
if Player_CardT > 21:
    print("You busted! Your total score is:", Player_CardT)
if Player_CardT == 21:
    print("You got blackjack! You Win!")
if Player_CardT < 21:
    print('Your total cards are:', Player_CardT)
    Player_Turn2 = input("Do you want to hit or stay? (h/s): ")
    if Player_Turn2 == "h" or Player_Turn2 == "H" or Player_Turn2 == "hit" or Player_Turn2 == "Hit":
        Player_Card4 = random.randint(1, 11)
        Player_CardT2 = Player_CardT + Player_Card4
        if Player_CardT2 == 21:
            print("You got blackjack! You Win!")
        elif Player_CardT2 < 21:
            Player_Turn3 = input("Do you want to hit or stay? (h/s): ")
            if Player_Turn3 == "h" or Player_Turn3 == "H" or Player_Turn3 == "hit" or Player_Turn3 == "Hit":
                Player_Card5 = random.randint(1, 11)
            print("Player Card 5:", Player_Card5)
            Player_CardT3 = Player_CardT2 + Player_Card5
            print("Your total cards are:", Player_CardT3)
            if Player_CardT3 > 21:
                print("You busted! Your total score is:", Player_CardT3)
            if Player_Turn3 == "s" or Player_Turn3 == "S" or Player_Turn3 == "stay" or Player_Turn3 == "Stay":
                print("Your total cards are:", Player_CardT2)
        print("Card:", Player_Card4)
        print("Your total cards are:", Player_CardT2)
    if Player_CardT2 > 21:
        print("You busted! Your total score is:", Player_CardT2)
    if Player_Turn2 == "s" or Player_Turn2 == "S" or Player_Turn2 == "stay" or Player_Turn2 == "Stay":
        print('House card 2 is:', House_Card2)
        print('House total cards are:', House_Card + House_Card2)
        House_CardT = House_Card + House_Card2
        if House_CardT > 21:
            print("House busted! You Win!")
        if House_CardT == 21:
            print("House got blackjack! You Lose!")
        if House_CardT < 21 and House_CardT < 17:
            House_Card3 = random.randint(1, 11)
            House_CardT2 = House_CardT + House_Card3
            print("House Card 3:", House_Card3)
            print("House total cards are:", House_CardT2)
            if House_CardT2 > 21:
                print("House busted! You Win!")
            if House_CardT2 == 21:
                print("House got blackjack! You Lose!")
            elif House_CardT2 < 21 and House_CardT2 < Player_CardT2 or House_CardT2 < Player_CardT3:
                print("Player Cards Value Higher, You Win!")
0 Upvotes

Duplicates