Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import shuffle
- import random, time
- global deck, dealerHand, playerHand, dealerHandScore
- cards = [x for x in range(2, 11)] + ["Jack", "Queen", "King", "Ace"]
- suits = ["Spade", "Heart", "Clubs", "Diamonds"]
- def shuffleDeck():
- return [[c, s] for c in cards for s in suits]
- deck = shuffleDeck()
- shuffle(deck)
- playerHand = random.sample(deck, 2)
- dealerHand = random.sample(deck, 2)
- dealerHandScore = 0
- dealerHidden = [dealerHand[0] + ["X"]]
- print("The house\'s hand is made out of %s." % (dealerHidden))
- def playerFunc():
- global deck, dealerHand, playerHand
- playerHandScore = 0
- for i in range(len(playerHand)):
- if playerHand[i][0] == "Jack" or playerHand[i][0] == "Queen" or playerHand[i][0] == "King":
- playerHandScore += 10
- elif playerHandScore <= 10 and playerHand[i][0] == "Ace":
- playerHandScore += 11
- elif playerHandScore > 10 and playerHand[i][0] == "Ace":
- playerHandScore += 1
- else:
- playerHandScore += playerHand[i][0]
- print("Sir\'s hand is made out of %s and is valued at %s.'" % (playerHand, playerHandScore))
- if playerHandScore < 21:
- playerHit = input("Do you want to hit or stand, sir? ")
- if playerHit.lower().startswith("h"):
- playerHand.append(random.choice(deck))
- playerFunc()
- elif playerHit.lower().startswith("s"):
- dealerFunc()
- elif playerHandScore == 21 and len(playerHand) > 2:
- dealerFunc()
- elif (playerHand[0][0] == "Ace" and (playerHand[1][0] == "Jack" or playerHand[1][0] == "Queen" or playerHand[1][0] == "King")) or\
- (playerHand[1][0] == "Ace" and (playerHand[0][0] == "Jack" or playerHand[0][0] == "Queen" or playerHand[0][0] == "King")):
- print("Sir wins.")
- elif playerHandScore > 21:
- print("Sir's gone bust!")
- def dealerFunc():
- global deck, dealerHand, playerHand, dealerHandScore
- for i in range(len(dealerHand)):
- if dealerHand[i][0] == "Jack" or dealerHand[i][0] == "Queen" or dealerHand[i][0] == "King":
- dealerHandScore += 10
- elif dealerHandScore <= 10 and dealerHand[i][0] == "Ace":
- dealerHandScore += 11
- elif dealerHandScore > 10 and dealerHand[i][0] == "Ace":
- dealerHandScore += 1
- else:
- dealerHandScore += dealerHand[i][0]
- def dealerScoringFunc():
- global deck, dealerHand, playerHand, dealerHandScore
- if dealerHandScore < 17:
- dealerHand.append(random.choice(deck))
- elif (dealerHand[0][0] == "Ace" and (dealerHand[1][0] == "Jack" or dealerHand[1][0] == "Queen" or dealerHand[1][0] == "King")) or\
- (dealerHand[1][0] == "Ace" and (dealerHand[0][0] == "Jack" or dealerHand[0][0] == "Queen" or dealerHand[0][0] == "King")):
- print("The house wins!")
- elif dealerHandScore > 21:
- print("The house's gone bust!")
- playerFunc()
Add Comment
Please, Sign In to add comment