Below is a portion of my Python code for a Blackjack project. I am using the portion of code for testing because I think I finally narrowed down where the problem is but I just can't figure out how to get it work.
The problem seems to be that when I use the following syntax for iterable-unpacking of 2 returned values the code uses the function call from the iterable-unpack rather than going back to the beginning of the code so nothing is returned in the function.
The syntax is variable_1, variable_2 = function()
I tested the keep_playing() function to see if I did something wrong there but when I use it with a simple hello_world() function it works just fine.
I searched for other ways to return multiple values that I can then assign to other variables for the program to use but can't find a solution there either.
def deal():
cards = [1,11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
player = []
dealer = []
while len(player) < 2:
player.append(random.choice(cards))
dealer.append(random.choice(cards))
return player, dealer
#this is ITERABLE UNPACK it separates the returned values from the deal() function and assigns them to their respective variables.
player, dealer = deal()
#sum the value of the cards
player_cards = sum(player)
dealer_cards = sum(dealer)
print(f"Your cards are {player}. Total = {player_cards}")
print(f"The dealer shows [{dealer[0]}, *]. Total = {dealer_cards}")
#the keep_playing function should start the deal function when the user types "Y" but it doesn't appear to
def keep_playing():
play_or_quit = input("Would you like to continue playing? Type 'Y' or 'N' ").lower()
if play_or_quit == 'y':
deal()
else:
print('Thank you for playing, good luck.')
keep_playing()