I have done the blackjack program but every time i run it shows an error here is the code:
P.S. I also need to show the value of the card[names of the cards e.g Jack etc
import random as r
def define_cards(c):
rank_suit=["ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"]
suit_rank=["clubs","spades","heatrts","diamonds"]
for suit in range(4):
for rank in range(13):
card_string=rank_suit[rank]+ " of "+ suit_rank[suit]
c.append(card_string)
return
def create_deck():
for i in range (52):
print[deck], i
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]*4
dealer = []
Player = []
def showHand():
hand = 0
for i in player: hand += i
print "The dealer is showing a %d" % dealer[0]
print "Your hand totals: %d (%s)" % (hand, Player)
def setup():
for i in range(2):
dealDealer = deck.append (r.randint(1, len(deck)-1)
dealplayer = deck.append(r.randint(1, len(deck)-1)
dealer.append(dealDealer)
Player.append(dealPlayer)
deck.pop(dealDealer)
deck.pop(dealPlayer)
setup()
ans=0
while ans != 'yes':
showHand()
ans = raw_input("Do you want to play another game: ")
if ans != 'yes':
dealPlayer = deck[r.randint(1, len(deck)-1)]
player.append(dealPlayer)
deck.pop(dealPlayer)
hand = 0
for i in dealer: hand += i
if not hand > 17:
dealDealer = deck[r.randint(1, len(deck)-1)]
dealer.append(dealDealer)
deck.pop(dealDealer)
hand = 0
for i in player: hand += i
if hand > 21:
print "BUST!"
Player = []
dealer = []
setup()
hand = 0
for i in dealer: hand +=i
if hand > 21:
print "Dealer Busts!"
Player = []
dealer = []
setup()
elif ans== 'no':
dHand = 0
PHand = 0
for i in dealer: dHand += i
for i in Player: pHand += i
if pHand > dHand:
print "the dealer is busted!"
dealer = []
Player = []
setup()
else:
print "you are busted!"
dealer = []
Player = []
setup()
print