Associating values in list with integers in Python

74 views Asked by At

I am working on a simple Blackjack game.

deck = ['Ace',2,3,4,5,6,7,8,9,10,'Jack','Queen','King']

card_1 = random.choice(deck)
card_2 = random.choice(deck)

def my_hand(card_1,card_2):
    total = card_1 + card_2
    if total > 21:
        return "Bust!"
    elif total == 21:
        return "Blackjack!"
    elif total < 21:
        return "Hit again?"

print card_1,'and',card_2 
my_hand(card_1,card_2)

How do I assign specific items in the list an integer value? Namely, I'd like to assign 'Ace' to the integer 1 or 11, and 'Jack', 'King', and 'Queen' equal to 10.

Thank you.

1

There are 1 answers

1
DYZ On BEST ANSWER

Use a dictionary (and I suggest that you convert all keys to strings):

deck = {'Ace':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'10':10,
 'Jack':10,'Queen':10,'King':10}