Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. import random
  2.  
  3. deck = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
  4. hand = []
  5. handValue = []
  6. input = []
  7.  
  8. def clearHand():
  9.     global hand
  10.     global handValue   
  11.     hand = []
  12.     handValue = []
  13.    
  14. def gameOver():
  15.     print "Game over.\n"
  16.     print "Type 'deal' to play again."
  17.     newGameInq()
  18.    
  19. def newGame():
  20.     print "Type 'deal' to start a new game!"
  21.     newGameInq()
  22.    
  23. def newGameInq():
  24.     input = raw_input(""">""")
  25.     if input == "deal":
  26.         newHand()
  27.     else:
  28.         print "That is not a hair question."
  29.         newGameInq()
  30.  
  31. def calc():
  32.     if 'J' in handValue:
  33.         handValue.remove("J")
  34.         handValue.append(10)
  35.     if 'Q' in handValue:
  36.         handValue.remove("Q")
  37.         handValue.append(10)
  38.     if 'K' in handValue:
  39.         handValue.remove("K")
  40.         handValue.append(10)
  41.     if 'A' in handValue:
  42.         handValue.remove("A")
  43.         handValue.append(11)
  44.  
  45. def newHand():
  46.     print "Dealing new hand!"
  47.     clearHand()
  48.     x = random.choice(deck)
  49.     hand.append(x)
  50.     handValue.append(x)
  51.     calc()
  52.     x = random.choice(deck)
  53.     hand.append(x)
  54.     handValue.append(x)
  55.     calc()
  56.     hand.sort()
  57.     print "You are holding:", hand
  58.     print "Total score:"
  59.     print sum(handValue[0:])
  60.     bustCheck()
  61.  
  62. def hitMe():
  63.     print "Dealing one new card!"
  64.     x = random.choice(deck)
  65.     hand.append(x)
  66.     handValue.append(x)
  67.     calc()
  68.     print "You are now holding:", hand
  69.     print "Total score:", sum(handValue[0:])
  70.     bustCheck()
  71.    
  72. def bustCheck():
  73.     if handValue < 21:
  74.         dealInq()
  75.     if handValue > 21:
  76.         gameOver()
  77.     else:
  78.         blackjack()
  79.        
  80. def dealInq():
  81.     print "Would you like a new card?"
  82.     input = raw_input(""">""")
  83.     if input == 'yes':
  84.         hitMe()
  85.     elif input == 'no':
  86.         gameOver()
  87.     else:
  88.         print "Invalid command. Please answer yes or no."
  89.         dealInq()
  90.        
  91. def blackjack():
  92.     print "Congratulations, you won!"
  93.     newGame()
  94.  
  95. print "\n\nJoker's Python Blackjack! :)\n\n"
  96.  
  97. newGame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement