def get_hand_value(cards):
    """Returns the value of the cards. Face cards are worth l0, aces are worth 11 or 1
    (this function picks the most suitable ace value)."""
    value = 0
    number_of_aces = 0

    # Add the value for the non-ace cards:
    for card in cards:
        rank = card[0]  # card is a tuple like (rank, suit)
        if rank == 'A':
            number_of_aces += 1
        elif rank in ('K', 'Q', 'J'):  # Face cards worth 10 points
            value += 10
        else:
            value += int(rank)  # Numbered cards are worth their number.

    # Add the value for the aces:
    value += number_of_aces  # Add 1 per ace
    for i in range(number_of_aces):
        # If another 10 can be added with busting, do so:
        if value + 10 <= 21:
            value += 10
    return value