[Tutor] How do you define the value of ACE in black jack

alan.gauld@bt.com alan.gauld@bt.com
Tue Feb 18 03:20:01 2003


> How would you define the value of ACE in python to the rules of Black
Jack?
 
Keeping it simple, I'd do this:
 

	import random
	 
	Jack = 10
	Queen = 10
	King = 10
	ACE = 11   # need initial definition
	 
	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 (firstcard == ACE or seccard == ACE) and sum > 21 :
	    sum = sum - 10
	    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:
	 

> but where else can I place the definition of ACE after all the values used
to define it 
> needs to have been stated!
 
Hopefully my (untested!) modification helps.
There are some other tricks we can play to make this easier, including using
functions 
as you suggested, but try this approach first...
 
Alan G.