Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- spades = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
- hearts = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
- clubs = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
- diamonds = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
- deck = []
- playerHand = []
- dealer = []
- bust = 0
- dealBust = 0
- t = 0
- def assignSuit():
- for w in range(13):
- spades[w] = spades[w] + " of Spades"
- for x in range(13):
- hearts[x] = hearts[x] + " of Hearts"
- for y in range(13):
- clubs[y] = clubs[y] + " of Clubs"
- for z in range(13):
- diamonds[z] = diamonds[z] + " of Diamonds"
- def shuffleDeck():
- global deck
- deck = spades + hearts + clubs + diamonds
- random.shuffle(deck)
- def gameStart():
- global playerHand
- global dealer
- global deck
- playerHand.append(deck.pop())
- dealer.append(deck.pop())
- playerHand.append(deck.pop())
- dealer.append(deck.pop())
- def determineCardValue():
- global playerHand
- value = 0
- for check in range(len(playerHand)):
- v = playerHand[check].partition(' ')[0]
- if(v=="Ace"):
- option = input("Would you like to value this card at 1 or 11?")
- value = value + option
- elif(v=="Two"):
- value = value + 2
- elif(v=="Three"):
- value = value + 3
- elif(v=="Four"):
- value = value + 4
- elif(v=="Five"):
- value = value + 5
- elif(v=="Six"):
- value = value + 6
- elif(v=="Seven"):
- value = value + 7
- elif(v=="Eight"):
- value = value + 8
- elif(v=="Nine"):
- value = value + 9
- else:
- value = value + 10
- return value
- def determineDealerValue():
- global dealer
- value = 0
- for check in range(len(dealer)):
- v = dealer[check].partition(' ')[0]
- if(v=="Ace"):
- if(value + 11 <= 21):
- value = value + 11
- else:
- value = value + 1
- elif(v=="Two"):
- value = value + 2
- elif(v=="Three"):
- value = value + 3
- elif(v=="Four"):
- value = value + 4
- elif(v=="Five"):
- value = value + 5
- elif(v=="Six"):
- value = value + 6
- elif(v=="Seven"):
- value = value + 7
- elif(v=="Eight"):
- value = value + 8
- elif(v=="Nine"):
- value = value + 9
- else:
- value = value + 10
- return value
- def playerTurn():
- global playerHand
- global deck
- global bust
- turn = 0
- while(turn==0):
- print "Your cards: "
- print playerHand
- choice = raw_input("Would you like to hit or stand? ")
- if(choice=="hit"):
- playerHand.append(deck.pop())
- if(determineCardValue()>21):
- print "Bust!"
- turn = 1
- bust = 1
- print "Your cards: "
- print playerHand
- elif(determineCardValue()==21):
- print "Blackjack!"
- turn = 1
- elif(choice=="stand"):
- turn=1
- print "The value you are staying at is " + str(determineCardValue()) + "."
- else:
- print "Please enter a valid choice."
- def dealerTurn():
- global dealer
- global deck
- global dealBust
- turn = 0
- while(turn==0):
- if(determineDealerValue()<17):
- dealer.append(deck.pop())
- elif(determineDealerValue()>21):
- turn = 1
- dealBust = 1
- else:
- turn = 1
- def determineWinner():
- global dealBust
- global bust
- global playerHand
- global dealer
- if(dealBust==1):
- if(bust==1):
- print "Tie!"
- else:
- print "You win!"
- elif(bust==1):
- if(dealBust==1):
- print "Tie!"
- else:
- print "Dealer wins!"
- else:
- if(determineCardValue()>determineDealerValue()):
- print "You win!"
- elif(determineCardValue()<determineDealerValue()):
- print "Dealer wins!"
- else:
- print "Tie!"
- def play():
- global t
- if(t==0):
- assignDeck()
- shuffleDeck()
- gameStart()
- playerTurn()
- dealerTurn()
- determineWinner()
- t = t + 1
- else:
- again = raw_input("Would you like to play again?(yes/no)")
- if(again=="yes"):
- assignDeck()
- shuffleDeck()
- playerHand = []
- dealer = []
- gameStart()
- playerTurn()
- dealerTurn()
- determineWinner()
- play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement