Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- deck = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
- hand = []
- handValue = []
- input = []
- def clearHand():
- global hand
- global handValue
- hand = []
- handValue = []
- def gameOver():
- print "Game over.\n"
- print "Type 'deal' to play again."
- newGameInq()
- def newGame():
- print "Type 'deal' to start a new game!"
- newGameInq()
- def newGameInq():
- input = raw_input(""">""")
- if input == "deal":
- newHand()
- else:
- print "That is not a hair question."
- newGameInq()
- def calc():
- if 'J' in handValue:
- handValue.remove("J")
- handValue.append(10)
- if 'Q' in handValue:
- handValue.remove("Q")
- handValue.append(10)
- if 'K' in handValue:
- handValue.remove("K")
- handValue.append(10)
- if 'A' in handValue:
- handValue.remove("A")
- handValue.append(11)
- def newHand():
- print "Dealing new hand!"
- clearHand()
- x = random.choice(deck)
- hand.append(x)
- handValue.append(x)
- calc()
- x = random.choice(deck)
- hand.append(x)
- handValue.append(x)
- calc()
- hand.sort()
- print "You are holding:", hand
- print "Total score:"
- print sum(handValue[0:])
- bustCheck()
- def hitMe():
- print "Dealing one new card!"
- x = random.choice(deck)
- hand.append(x)
- handValue.append(x)
- calc()
- print "You are now holding:", hand
- print "Total score:", sum(handValue[0:])
- bustCheck()
- def bustCheck():
- if handValue < 21:
- dealInq()
- if handValue > 21:
- gameOver()
- else:
- blackjack()
- def dealInq():
- print "Would you like a new card?"
- input = raw_input(""">""")
- if input == 'yes':
- hitMe()
- elif input == 'no':
- gameOver()
- else:
- print "Invalid command. Please answer yes or no."
- dealInq()
- def blackjack():
- print "Congratulations, you won!"
- newGame()
- print "\n\nJoker's Python Blackjack! :)\n\n"
- newGame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement