I'm currently having an issue where I play a round of blackjack on the code I created, but keep losing. My score will be <21 but still more than the dealer and I will lose. I am pretty new to coding so any help is appreciated, thanks.
def FinalScore():
global bank, bet
# different win conditions
# pays the player their original bet * 2
if player_score == dealer_score and player_score <= 21:
print("It's a tie!")
bank = bank + bet
print("You currently have $",bank,"left.")
Restart()
elif player_score > 21:
print("You lost!")
print("You currently have $",bank,"left.")
Restart()
elif player_score < 21 and dealer_score > player_score:
print("You lost!")
print("You currently have $",bank,"left.")
Restart()
elif player_score > dealer_score and player_score <= 21:
print("You win!")
bank = bet + bet + bank
print("You currently have $",bank,"left.")
Restart()
elif dealer_score > 21 and player_score <= 21:
print("You win!")
bank = bet + bet + bank
print("You currently have $",bank,"left.")
Restart()
I tried rearranging the order of the win conditions and it did change some outcomes, but ultimately it was still finnicky. I think there is a better way to do this that I am not aware of.
You have a lot of conditions; In BJ, you lose if you burn (>21); but after that you win if dealer burn; after your score in compared with dealer;