"""Functions to help play and score a game of blackjack.
How to play blackjack: https://bicyclecards.com/how-to-play/blackjack/
"Standard" playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
"""defvalue_of_card(card):"""Determine the scoring value of a card.
:param card: str - given card.
:return: int - value of a given card. See below for values.
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
2. 'A' (ace card) = 1
3. '2' - '10' = numerical value.
"""ifcardin['J','Q','K']:return10elifcard=='A':return1elifint(card)>=2orint(card)<=10:returnint(card)defhigher_card(card_one,card_two):"""Determine which card has a higher value in the hand.
:param card_one, card_two: str - cards dealt in hand. See below for values.
:return: str or tuple - resulting Tuple contains both cards if they are of equal value.
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
2. 'A' (ace card) = 1
3. '2' - '10' = numerical value.
"""ifcard_oneiscard_two:returncard_one,card_twoelifvalue_of_card(card_one)==value_of_card(card_two):returncard_one,card_twoelifvalue_of_card(card_one)>value_of_card(card_two):returncard_oneelse:returncard_twodefvalue_of_ace(card_one,card_two):"""Calculate the most advantageous value for the ace card.
:param card_one, card_two: str - card dealt. See below for values.
:return: int - either 1 or 11 value of the upcoming ace card.
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
2. 'A' (ace card) = 11 (if already in hand)
3. '2' - '10' = numerical value.
"""ifcard_one=='A'orcard_two=='A':return1points=value_of_card(card_one)+value_of_card(card_two)ifpoints<=10:return11else:return1defis_blackjack(card_one,card_two):"""Determine if the hand is a 'natural' or 'blackjack'.
:param card_one, card_two: str - card dealt. See below for values.
:return: bool - is the hand is a blackjack (two cards worth 21).
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
2. 'A' (ace card) = 11 (if already in hand)
3. '2' - '10' = numerical value.
"""hand=card_one,card_two# any(iterable)
# Return True if any element of the iterable is true. If the iterable is empty, return False.
# https://docs.python.org/3/library/functions.html#any
return'A'inhandandany(cardinhandforcardin('10','J','Q','K'))defcan_split_pairs(card_one,card_two):"""Determine if a player can split their hand into two hands.
:param card_one, card_two: str - cards dealt.
:return: bool - can the hand be split into two pairs? (i.e. cards are of the same value).
"""returnvalue_of_card(card_one)==value_of_card(card_two)defcan_double_down(card_one,card_two):"""Determine if a blackjack player can place a double down bet.
:param card_one, card_two: str - first and second cards in hand.
:return: bool - can the hand can be doubled down? (i.e. totals 9, 10 or 11 points).
"""points=value_of_card(card_one)+value_of_card(card_two)return9<=points<=11