The value of ACE in Black Jack

Tim Rowe tim at remove_if_not_spam.digitig.co.uk
Fri Feb 21 11:56:38 EST 2003


Ole Jensen wrote:
> In Black Jack the value of the ACE depends on the sum of your cards if the
> sum is lower than 21, the value of your ACE is 11
> however if the sum of your cards increase to more than 21(if ace counts for
> 11) then your ACE drops to the value of one.
> 
> How would you define the value of ACE in python to the rules of Black Jack?

As others have suggested, a list may be the way to go here.  Something like:

def totals(hand):
    result = []
    for i in range(0, hand.count(1) + 1):
       result.append(reduce(lambda a, b: a + b,hand, 0) + 10 * i)
    return result


 >>> totals([1, 2, 3, 1])
[7, 17, 27]
 >>> totals([2, 3, 4, 5])
[14]

Just pick out the biggest less than or equal to 21 (or declare bust if 
they're all over 21).





More information about the Python-list mailing list