import random
def p_deal(pd,pc,ps):
pc.append(random.choice(pd))
ps = sum(pc)
print(pc,ps)
if ps < 22:
main(deck,p_cards,p_sum,d_cards,d_sum)
else:
print('busted, you lose')
def d_deal(dd,dc,ds):
if ds > 21:
print('Computer bust. You win.')
else:
if ds > ps:
print(pc,ps)
def main(deck0,pcards,psum,dcards,dsum):
inp = input('hit or stay: ')
if inp == 'hit':
p_deal(deck0,pcards,psum)
elif inp == 'stay':
d_deal(deck0,dcards,dsum)
deck = [1,2,3,4,5,6,7,8,9,10,10,10,10,11]
d_cards = []
p_cards = []
p_cards.append(random.choice(deck))
p_cards.append(random.choice(deck))
d_cards.append(random.choice(deck))
d_cards.append(random.choice(deck))
p_sum = sum(p_cards)
print("You have:", p_cards, "\nTotal:", p_sum)
d_sum = sum(d_cards)
print("Dealer has:", d_cards, "\nTotal:", d_sum)
main(deck,p_cards,p_sum,d_cards,d_sum)
Hi, just started Python as my first language a couple of weeks ago. I am building a simplified version of BlackJack / 21.
I managed to get most of the left side of the flow chart, but the problem begins when I choose "stay".
I am having a hard time passing the 'updated variables' of pc and ps from p_deal() over to d_deal(). I've tried using 'return' but with return, it will not allow the function to loop and give the option to 'hit' when ps is under 22.
Any help would be appreciated. Thank you.