Backjack program

This is the place for queries that don't fit in any of the other categories.

Backjack program

Postby lundyman » Thu Dec 05, 2013 9:42 pm

Can someone please fix this code and tell me what it does? I will be eternally grateful...

Code: Select all
from random import randrange

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

def dealHand():
    total = 0
    haveAce = False
    while total < 17:
        card = randrange(1,14)
        if card == 1:
           haveAce = True
        total = total + BJValue(card)
        if haveAce:
            total = adjustForAce(total)
    return total
def BJValue(card):
    if card > 10:
        return 10
        return card

def adjustForAce(total):
    if 16 < total + 10 < 22:
        return total + 10
        return total

if __name__ == '__main__':
Last edited by micseydel on Thu Dec 05, 2013 9:52 pm, edited 2 times in total.
Reason: Code tags, locked OP, better title.
Posts: 1
Joined: Thu Dec 05, 2013 9:38 pm

Re: Backjack program

Postby micseydel » Thu Dec 05, 2013 9:50 pm

Hello, and welcome to the forum. Make sure to read this before making your next post.

Added in edit: make sure to make an effort toward academic honesty here. We don't want to ruin your Ultimate career but clear "do it for me" posts will have their schools contacted.
Due to the reasons discussed here we will be moving to on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 10 guests