mariang_09

Untitled

Dec 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.70 KB | None | 0 0
  1. from random import shuffle
  2. import random, time
  3. global deck, dealerHand, playerHand, dealerHandScore
  4.  
  5. cards = [x for x in range(2, 11)] + ["Jack", "Queen", "King", "Ace"]
  6. suits = ["Spade", "Heart", "Clubs", "Diamonds"]
  7.  
  8. def shuffleDeck():
  9.     return [[c, s] for c in cards for s in suits]
  10.  
  11. deck = shuffleDeck()
  12. shuffle(deck)
  13.  
  14. playerHand = random.sample(deck, 2)
  15.  
  16. dealerHand = random.sample(deck, 2)
  17. dealerHandScore = 0
  18. dealerHidden = [dealerHand[0] + ["X"]]
  19. print("The house\'s hand is made out of %s." % (dealerHidden))
  20.  
  21.  
  22. def playerFunc():
  23.     global deck, dealerHand, playerHand
  24.  
  25.     playerHandScore = 0
  26.  
  27.     for i in range(len(playerHand)):
  28.  
  29.         if playerHand[i][0] == "Jack" or playerHand[i][0] == "Queen" or playerHand[i][0] == "King":
  30.             playerHandScore += 10
  31.  
  32.         elif playerHandScore <= 10 and playerHand[i][0] == "Ace":
  33.             playerHandScore += 11
  34.  
  35.         elif playerHandScore > 10 and playerHand[i][0] == "Ace":
  36.             playerHandScore += 1
  37.  
  38.         else:
  39.             playerHandScore += playerHand[i][0]
  40.  
  41.     print("Sir\'s hand is made out of %s and is valued at %s.'" % (playerHand, playerHandScore))
  42.  
  43.     if playerHandScore < 21:
  44.         playerHit = input("Do you want to hit or stand, sir? ")
  45.  
  46.         if playerHit.lower().startswith("h"):
  47.             playerHand.append(random.choice(deck))
  48.             playerFunc()
  49.  
  50.         elif playerHit.lower().startswith("s"):
  51.             dealerFunc()
  52.  
  53.     elif playerHandScore == 21 and len(playerHand) > 2:
  54.         dealerFunc()
  55.  
  56.     elif (playerHand[0][0] == "Ace" and (playerHand[1][0] == "Jack" or playerHand[1][0] == "Queen" or playerHand[1][0] == "King")) or\
  57.         (playerHand[1][0] == "Ace" and (playerHand[0][0] == "Jack" or playerHand[0][0] == "Queen" or playerHand[0][0] == "King")):
  58.             print("Sir wins.")
  59.  
  60.     elif playerHandScore > 21:
  61.         print("Sir's gone bust!")
  62.  
  63. def dealerFunc():
  64.     global deck, dealerHand, playerHand, dealerHandScore
  65.    
  66.     for i in range(len(dealerHand)):
  67.  
  68.         if dealerHand[i][0] == "Jack" or dealerHand[i][0] == "Queen" or dealerHand[i][0] == "King":
  69.             dealerHandScore += 10
  70.  
  71.         elif dealerHandScore <= 10 and dealerHand[i][0] == "Ace":
  72.             dealerHandScore += 11
  73.  
  74.         elif dealerHandScore > 10 and dealerHand[i][0] == "Ace":
  75.             dealerHandScore += 1
  76.  
  77.         else:
  78.             dealerHandScore += dealerHand[i][0]
  79.  
  80.  
  81.  
  82.  
  83. def dealerScoringFunc():
  84.     global deck, dealerHand, playerHand, dealerHandScore
  85.  
  86.     if dealerHandScore < 17:
  87.         dealerHand.append(random.choice(deck))
  88.  
  89.     elif (dealerHand[0][0] == "Ace" and (dealerHand[1][0] == "Jack" or dealerHand[1][0] == "Queen" or dealerHand[1][0] == "King")) or\
  90.         (dealerHand[1][0] == "Ace" and (dealerHand[0][0] == "Jack" or dealerHand[0][0] == "Queen" or dealerHand[0][0] == "King")):
  91.         print("The house wins!")
  92.  
  93.     elif dealerHandScore > 21:
  94.         print("The house's gone bust!")
  95.  
  96. playerFunc()
Add Comment
Please, Sign In to add comment