The value of ACE in Black Jack

Ole Jensen ole_jensen at dbmail.dk.NO_SPAM
Mon Feb 17 16:08:27 EST 2003


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?

Im sure the best way is to make some sort of a function but as a nooB, im
not really sure how to get that to work (i might be able to make the
function but Im not sure how to integrate it with the rest of the code)...

this is how I've done so far:

Start of code:

import random

Jack = 10
Queen = 10
King = 10

cards = ["dummy", ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King]

firstcard = cards[random.randrange(1,14)]
seccard = cards[random.randrange(1,14)]
sum = firstcard + seccard

# ACE definition
if sum + 11 <= 21:
    ACE = 11
elif sum + 11 > 21:
    ACE = 1

print "Card one:", firstcard, "\t", "Card two:", seccard, "\t", "Sum:", sum
crd = ["three:", "four:", "five:"]

print "do you want to:\n1 - hit \n2 - stand"
hitstand = input(">>> ")

j = 0
while hitstand == 1:
    newcard = cards[random.randrange(1,14)]
    sum = sum + newcard
    print "card "+crd[j], newcard, "\t", "\t", "sum", sum
    j = j + 1
    print "do you want to:\n1 - hit \n2 - stand"
    hitstand = input(">>> ")

End of code:

in my defintion of ACE it seems that ACE is always 11, which might not be
surprising as it uses the sum of the first to cards (im guessing) that are
always lower than 21(or equal to).
but where else can I place the definition of ACE after all the values used
to define it needs to have been stated!


any help appriciated

Olé






More information about the Python-list mailing list