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

You should give more information about the error (line, type, etc) so we could come up with a solution without running it. There is a SyntaxError at line 28 and 29, one closing bracket is missing. You should turn highlighting matching brackets on in your text editor/IDE :) There is another error at line 29 (dealPlayer instead of dealplayer). Still not done, at line 26 and 27 there is an unclear part: append does not have a return value. I don't really know what you meant to do here. Tell me, so I can probably fix it.

I also have a suggestion: you should store rank_suit and suit_rank as global variables, so they don't have to be initialized multiple times.

So what you are you are saying is i need to change line 26 and 27? which i've already tried and it still gives back the same error.

You have to add closing brackets, because this is still open:

(r.randint(1, len(deck)-1)
1         2      3    1  2 (3)

But this line

dealDealer = deck.append (r.randint(1, len(deck)-1)

makes no sense: it's like saying dealDealer = None. What do you want to do here?

Have you tried ever making a game if blackjack where the dealer plays against the player as it is this is one of a kind and that is how you deal cards to the dealer that is not the major problem bro it is something else entirely different.

P.S. If it becomes too hard to solve forget it i will start a new version of it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.