Python Blackjack game - referenced before assignment -
So, my personal challenge to make a simple Blackjack game Dragon this way I went about it :
singlePlayerCard = random.choice (availableCards) singlePlayerCard2 = random.choice (availableCards) if (singlePlayerCard == [1,2,3, 4,5,6,7,8,9 , 10]): singlePlayerCardValue = singlePlayerCard if (singlePlayerCard2 == [1,2,3,4,5,6,7,8,9,10]): singlePlayerCard2Value = singlePlayerCard2 singlePlayerCardValueTotal = singlePlayerCardValue + singlePlayerCard2Value print
< / pre>when it comes to
print singlePlayerCardValueTotal
this tells me either (% singlePlayerCardValueTotal "your Ard Total% I values ") thatsinglePlayerCalValue
orsinglePlayerCard2Value
has been referenced before assignment. This is a bit confusing as I have taken this issue with another simple program in the past, but the structure is different here. In addition to the above issue, it was working fine. If you have the time, please provide me a better solution for some areas if necessary.As always, thanks in advance! After the text "itemprop =" text ">
if you have been told in your comment," referenced before work "means that
It seems that your problem is:
if (singleplayercard == [1,2,3,4,5,6, 7,8,9, 10]): singlePlayerCardValue = singlePlayerCard
your singlePlayerCard
never in list equal to> [1 , 2,3,4,5,6,7,8,9,10]
, you will not specify a value for a value when it is a number card.
==
The operator is not a way to check whether the value is included in a list or not. Do ,:
if (singlePlayerCard [1,2,3,4,5,6,7,8,9,10]): singlePlayerCardValue = singlePlayerCard
Comments
Post a Comment