bobbyoutlaw 0 Newbie Poster

Ok Here's what the teacher's assignment to me was....In most actual Blackjack games the dealer starts with one upcard showing. Your task is to calculate the dealer's bust probability for each possible starting value. Your program should report a value for each possible starting card from Ace (1) to Ten. (You don't need to go beyond 10, since all facecards have the same value in Blackjack

This is what I got so far, but don't know where to go from here....I don't know how to report a value for each possible starting card, and am stuck right now...

def main():
    print "Simulation of a Blackjack dealer.\n"
    n = input("How many trials? ")
    busts = 0
    for i in range(n):
        points = dealHand()
        if points > 21:
            busts = busts + 1
    print "In %d hands dealer busted %d times." % (n, busts)
    print "Estimated prob =", float(busts)/n

# This function simulates the dealing of a single hand.
def dealHand():
    total = 0
    haveAce = False
    while total < 17:
   # This randomly generates a card.
   # Note that 11 is Jack, 12 is Queen, 13 is King
   # Here we care about distinguishing facecards, because
   # we want to generate the right probability
   # distribution of cards.
        card = randrange(1,14)
        if card == 1:
           haveAce = True
        total = total + BJValue(card)
        if haveAce:
            total = adjustForAce(total)
    return total

# This returns the Blackjack value of a card.  All facecards are 10.
def BJValue(card):
    if card > 10:
        return 10
    else:
        return card

# This is slightly tricky.  It checks if total+10 is between 17 and 21.
def adjustForAce(total):
    if 16 < total + 10 < 22:
        return total + 10
    else:
        return total

if __name__ == '__main__':
    main()
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.