importsysFACE_CARDS=['J','Q','K']defscore_hand(hand):'''
Calculate the total score of the hand.
'''hand_score=0forcardinhand:ifcardinFACE_CARDS:hand_score+=10continueifcard=='A':hand_score+=1ifhand_score<12:hand_score+=10continuetry:hand_score+=int(card)continueexceptValueError:print('Invalid card in hand: {}'.format(card))exceptTypeError:print('Card is an invalid type: {}'.format(type(card)))returnhand_scoreprint(str(score_hand(['A'])))print(str(score_hand(['5','4','3','2','A','K'])))print(str(score_hand(['5','3','7'])))print(str(score_hand(['A','J'])))print(str(score_hand(['A','10','A'])))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Python: