All pastes #395638 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-03-15 05:22 UTC
rendered paste body
VALUES = ("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A")
SUITS = ("S", "H", "D", "C")
deck = ()
for first in VALUES :
    for suit in SUITS :
        card = first + suit
        deck += (card,)

while len(deck) > 10:

    import random

    playerHand = ()
    pos = random.randrange(len(deck))
    card = deck [pos]
    playerHand+=(card, )
    deck = deck[0:pos]+deck[pos+1:]

    pos = random.randrange(len(deck))
    card = deck [pos]
    playerHand+=(card, )
    deck = deck[0:pos]+deck[pos+1:]

    dealerHand = ()
    pos = random.randrange(len(deck))
    card = deck [pos]
    dealerHand+=(card, )
    deck = deck[0:pos]+deck[pos+1:]

    pos = random.randrange(len(deck))
    card = deck [pos]
    dealerHand+=(card, )
    deck = deck[0:pos]+deck[pos+1:]

    print "\nDealer is showing", card,"."

    def handCount (hand) :
        total = 0
        for num in hand :
            for value in range (2,11):
                if str(value) in num:
                    total += value

            if "J" in num:
                total+= 10
            if "Q" in num:
                total+= 10
            if "K" in num:
                total+= 10
            if "A" in num:
                total += 1
            if "A" in num and total < 12:
                total +=10

        return total

    print "You have", playerHand, "that adds to", handCount(playerHand),"."

    answer = ""
    while answer != "no" and handCount(playerHand) < 22:
        answer = raw_input("Do you wish another card? (yes or no)? ")
        pos = random.randrange(len(deck))
        card = deck [pos]
        playerHand+=(card, )
        deck = deck[0:pos]+deck[pos+1:]
        print "You have", playerHand, "that adds to", handCount(playerHand)
    
    print "The dealer has", dealerHand, "that adds to", handCount(dealerHand),"."