Here is the first part of my code for a blackjack simulator I'm making. The program is supposed to be one player playing with basic strategy against the dealer. Everything was working fine until I added the 'if' part of the deal_card(x) function.
So, if I run deal_card(phand), the set phand will have a card added to it. However, the if statement part won't affect phand at all. I'm trying to understand how the first part of the deal_card(x) function will affect whatever x is, but the latter (if) part doesn't change it.
number_of_decks = 6
standard_deck = sorted(4*[2,3,4,5,6,7,8,9,10,10,10,10,11])
shoe = sorted(number_of_decks*standard_deck)
removed=[]
results=[]
from random import randint
dhand=[]
phand=[]
def deal_card(x):
card=shoe[randint(0,4*13*6-1-len(removed))]
shoe.remove(card)
removed.append(card)
x.append(card)
if sum(x)>21 and sorted(x)[len(x)-1]==11:
x=sorted(x)
x[len(x)-1]=1
return x
This is so frustrating that it's making me lose my mind. So I'd be really grateful for anybody's help.
Thank you.
What I have tried:
I have tried Googling the answer but nobody really seems to be having the same issue I'm having.