<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 = {&quot;Ace&quot;, &quot;Two&quot;, &quot;Three&quot;,
&quot;Four&quot;, &quot;Five&quot;, &quot;Six&quot;, &quot;Seven&quot;,
&quot;Eight&quot;, &quot;Nine&quot;, &quot;Ten&quot;, &quot;Jack&quot;,
&quot;Queen&quot;, &quot;King&quot;}<br>
card_types = {&quot;Diamond&quot;, &quot;Heart&quot;, &quot;Spade&quot;,
&quot;Club&quot;}<br>
bet = 0<br>
playertotal = 0<br>
comp_total = 0<br>
&nbsp;<br>
def menu():<br>
&nbsp;&nbsp;&nbsp; print &quot;1. Bet and play.&quot;<br>
&nbsp;&nbsp;&nbsp; print &quot;2. Cash out and Exit&quot;<br>
&nbsp;<br>
def option():<br>
&nbsp;&nbsp;&nbsp; return int(raw_input(&quot;Menu choice: &quot;))<br>
&nbsp;<br>
def card_choice():<br>
&nbsp;&nbsp;&nbsp; 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="">&nbsp;def types():<br>
&nbsp;&nbsp;&nbsp; return random.choice(range(1,5)<br>
&nbsp;<br>
def player_cards():<br>
&nbsp;&nbsp;&nbsp; print a,&quot; of &quot;,t1<br>
&nbsp;&nbsp;&nbsp; print b,&quot; of &quot;,t2<br>
&nbsp;<br>
print &quot;Blackjack&quot;<br>
print &quot;By Nathan Pinno&quot;<br>
while 1:<br>
&nbsp;&nbsp;&nbsp; menu()<br>
&nbsp;&nbsp;&nbsp; choice = option()<br>
&nbsp;&nbsp;&nbsp; if choice == 1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bet = int(raw_input(&quot;How
much do you want to bet: &quot;)</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 &gt; new_cash? Endless loop printing the Sorry...
forever<br><br>
<blockquote type=cite class=cite cite="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
while 1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if bet
&gt; new_cash:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print &quot;Sorry, you don't have that much cash! Your total cash is:
$&quot;,new_cash<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
else:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
break<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a,b = card_choice()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t1,t2 = types()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if t1 == 1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t1 =
card_types[0]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif t1 == 2:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t1 =
cardtypes[1]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif t1 == 3:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t1 =
cardtypes[2]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t1 =
cardtypes[t1]<br><br>
<blockquote type=cite class=cite cite="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if a == 1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a =
cards[0]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
playertotal = playertotal + 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif a == 2:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a =
cards[1]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
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>