# something close to blackjack

import random

cards = {'ace':1,'two':2,'three':3,'four':4,'five':5,'six':6,
         'seven':7,'eight':8,'nine':9,'ten':10,'jack':10,
         'queen':10,'king':10}

# example: the_hand = ['king','two']
def handvalue(the_hand):
    total = 0
    for cardname in the_hand:
        total += cards[cardname]
    return total
    
# example: the_hand = ['king','two']
def display_hand(the_hand):
    print(f'Hand is: {the_hand}')
    hv = handvalue(the_hand)
    print(f'Value of the hand is: {hv}')


def deal_a_hand():
    cardnames = list(cards.keys())
    player_hand = []
    player_hand.append(random.choice(cardnames))
    player_hand.append(random.choice(cardnames))
    # player_hand has 2 cards
    display_hand(player_hand)
    while True:
        hv = handvalue(player_hand)
        if hv == 21:
            print('Congratulations your hand is 21.')
            break
        elif hv > 21:
            print('Bust')
            break
        userchoice = input('Hit or Stay')
        if userchoice == 'Hit' or userchoice == 'hit':
            player_hand.append(random.choice(cardnames))
            display_hand(player_hand)
        else:
            # assume they typed Stay
            print('OK, your final hand is:')
            display_hand(player_hand)
            print()
            break

deal_a_hand()
