Nathan Pinno falcon3166 at hotmail.com
Wed Aug 3 21:23:40 CEST 2005

```Playertotal is for calculating the total of the player's hand. This is important, because if the player's total is greater than 21, he loses in Blackjack. B is for the second card in the player's hand and t2 was for the second card's type (i.e Heart, Diamond, Club, or Spade)
----- Original Message -----
From: Bob Gailer
To: Nathan Pinno ; Tutor mailing list ; Yoo, Danny
Sent: Wednesday, August 03, 2005 1:03 PM

At 11:36 AM 8/3/2005, Nathan Pinno wrote:

Here is the code then:

I'll throw in some suggestions. 1 - check for balanced parentheses. This has bit you before and you have several lines below with unbalanced parentheses. 2 - since Python indexes start at 0, take advantage of this. Use random.choice(range(13) and use the value to index the cards list.

#This is code for a blackjack game.
import random
cash = 0
new_cash = 100
cards = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}
card_types = {"Diamond", "Heart", "Spade", "Club"}
bet = 0
playertotal = 0
comp_total = 0

print "1. Bet and play."
print "2. Cash out and Exit"

def option():

def card_choice():
return random.choice(range(1,14)

>This will return one number. The statement below (a,b = card_choice()) expects a tuple of 2 numbers to be returned.

How do I make it return two numbers?
def types():
return random.choice(range(1,5)

def player_cards():
print a," of ",t1
print b," of ",t2

print "Blackjack"
print "By Nathan Pinno"
while 1:
choice = option()
if choice == 1:
bet = int(raw_input("How much do you want to bet: ")

Something is wrong with the indentation below. Assuming the if and else following the while are indented more, you have a BIG problem. What will happen if bet > new_cash? Endless loop printing the Sorry... forever

Thanks, I forgot about that. I have to add bet = int(raw_input("Bet: "))

while 1:
if bet > new_cash:
print "Sorry, you don't have that much cash! Your total cash is: \$",new_cash
else:
break
a,b = card_choice()
t1,t2 = types()
if t1 == 1:
t1 = card_types
elif t1 == 2:
t1 = cardtypes
elif t1 == 3:
t1 = cardtypes
else:
t1 = cardtypes

Why not just use the random integer as an index? If you use range(13) these if/elifs become
t1 = cardtypes[t1]

if a == 1:
a = cards
playertotal = playertotal + 1
elif a == 2:
a = cards
playertotal = playertotal + 2

Same thing here.
What are the functions of b, t2, and playertotal? Especially for those of us who don't know blackjack.

Does that help?

It helps some, but if you could answer my question above about how to return two random numbers, it would be appreciated.

Bob Gailer
phone 510 978 4454
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050803/c4000bd7/attachment.htm
```