I wrote this function to "score" hands for a Python blackjack game (I know aces can be 1 or 11, that's a future problem to figure out). The input is a list of tuples (cards), and the rank can be either 2-10 or A, J, K, or Q.
I'm sometimes getting a TypeError that reads TypeError: unsupported operand type(s) for +: 'int' and 'str'
in reference to score = score + rank
. I'm not sure why there's an issue though, because if it gets to that point the rank must be an int. Anyone see the issue?
def analyzeHand(hand):
score = 0
for card in hand:
rank = card[0]
if (rank == 'A'):
score = score + 11
if (rank == 'K' or rank == 'Q' or rank == 'J'):
score = score + 10
else:
score = score + rank
return score