<html>
<body>
At 11:36 AM 8/3/2005, Nathan Pinno wrote:<br>
<blockquote type=cite class=cite cite="">Here is the code
then:</blockquote><br>
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.<br><br>
<blockquote type=cite class=cite cite="">#This is code for a blackjack
game.<br>
import random<br>
cash = 0<br>
new_cash = 100<br>
cards = {"Ace", "Two", "Three",
"Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack",
"Queen", "King"}<br>
card_types = {"Diamond", "Heart", "Spade",
"Club"}<br>
bet = 0<br>
playertotal = 0<br>
comp_total = 0<br>
<br>
def menu():<br>
print "1. Bet and play."<br>
print "2. Cash out and Exit"<br>
<br>
def option():<br>
return int(raw_input("Menu choice: "))<br>
<br>
def card_choice():<br>
return random.choice(range(1,14)</blockquote><br>
This will return one number. The statement below (a,b = card_choice())
expects a tuple of 2 numbers to be returned.<br><br>
<blockquote type=cite class=cite cite=""> def types():<br>
return random.choice(range(1,5)<br>
<br>
def player_cards():<br>
print a," of ",t1<br>
print b," of ",t2<br>
<br>
print "Blackjack"<br>
print "By Nathan Pinno"<br>
while 1:<br>
menu()<br>
choice = option()<br>
if choice == 1:<br>
bet = int(raw_input("How
much do you want to bet: ")</blockquote><br>
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<br><br>
<blockquote type=cite class=cite cite="">
while 1:<br>
if bet
> new_cash:<br>
print "Sorry, you don't have that much cash! Your total cash is:
$",new_cash<br>
else:<br>
break<br>
a,b = card_choice()<br>
t1,t2 = types()<br>
if t1 == 1:<br>
t1 =
card_types[0]<br>
elif t1 == 2:<br>
t1 =
cardtypes[1]<br>
elif t1 == 3:<br>
t1 =
cardtypes[2]<br>
else:<br>
t1 =
cardtypes[3]</blockquote><br>
Why not just use the random integer as an index? If you use range(13)
these if/elifs become<br>
t1 =
cardtypes[t1]<br><br>
<blockquote type=cite class=cite cite="">
if a == 1:<br>
a =
cards[0]<br>
playertotal = playertotal + 1<br>
elif a == 2:<br>
a =
cards[1]<br>
playertotal = playertotal + 2</blockquote><br>
Same thing here. <br>
What are the functions of b, t2, and playertotal? Especially for those of
us who don't know blackjack.<br><br>
Does that help?<br>
<x-sigsep><p></x-sigsep>
<font size=2>Bob Gailer<br>
phone 510 978 4454 </font></body>
</html>