import random playAgain = 'yes' print "This is a 2-player 21 game... Hope you enjoy!" while playAgain == 'yes' or playAgain == 'y': turn1 = True turn2 = True stand1 = False stand2 = False busted1 = False busted2 = False game = True gameEnd1 = False gameEnd2 = False player1 = raw_input("Player 1, enter your name: ") player2 = raw_input("Player 2, enter your name: ") numberStored1 = random.randint(1, 11) numberStored2 = random.randint(1, 11) print player1 + ", your first card gives you a hand value of " + str(numberStored1) + "." print player2 + ", your first card gives you a hand value of " + str(numberStored2) + "." while game: while turn1 is True: turnAction = raw_input(str(player1) + ", do you wish to hit or stand? ") if turnAction == "hit": numberStored1 = numberStored1 + random.randint(1, 11) turn1 = False elif turnAction == "stand": numberStored1 = numberStored1 turn1 = False stand1 = True else: print "Incorrect input. Please enter 'hit' or 'stand' to continue." while turn2 is True: turnAction = raw_input(str(player2) + ", do you wish to hit or stand? ") if turnAction == "hit": numberStored2 = numberStored2 + random.randint(1, 11) turn2 = False elif turnAction == "stand": numberStored2 = numberStored2 turn2 = False stand2 = True else: print "Incorrect input. Please enter 'hit' or 'stand' to continue." print player1 + ", you currently have a hand value of " + str(numberStored1) + "." print player2 + ", you currently have a hand value of " + str(numberStored2) + "." if busted1 is False and busted2 is False: if numberStored1 > 21 and numberstored2 <= 21: print str(player1) + " went bust! " busted1 = True if stand2 is False: print str(player2) + " may still take turns." turn2 = True elif numberStored2 > 21 and numberstored1 <= 21: print str(player2) + " went bust! " busted2 = True if stand1 is False: print str(player1) + " may still take turns." turn1 = True elif numberStored1 > 21 and numberStored2 > 21: print "Both players went bust. Oh well!" busted1 = True busted2 = True else: if stand1 is True and stand2 is False: print str(player2) + " still has a decision." turn2 = True elif stand2 is True and stand1 is False: print str(player1) + " still has a decision." turn1 = True elif stand1 is True and stand2 is True: pass elif busted1 is True: if numberStored2 > 21: print "Oh, " + str(player2) + " went bust as well! Players tie in bust." elif stand2 is False: print str(player2) + " still has a decision, then!" turn2 = True elif busted2 is True: if numberStored1 > 21: print "Oh, " + str(player1) + " went bust as well! Players tie in bust." elif stand1 is False: print str(player1) + " still has a decision, then!" turn1 = True if busted1 or stand1: gameEnd1 = True if busted2 or stand2: gameEnd2 = True if gameEnd1 and gameEnd2: game = False print "The game is over!" if busted1: print str(player1) + " went bust with a score of " + str(numberStored1) + "." else: print str(player1) + " had a final score of " + str(numberStored1) + "." if busted2: print str(player2) + " went bust with a score of " + str(numberStored2) + "." else: print str(player2) + " had a final score of " + str(numberStored2) + "." if not busted1 and not busted2: if numberStored1 > numberStored2: print str(player1) + " is the winner!" elif numberStored2 > numberStored1: print str(player2) + " is the winner!" elif busted1: print str(player2) + " is the winner!" elif busted2: print str(player1) + " is the winner!" print "Good game, " + str(player1) + " and " + str(player2) + "!" playAgain = raw_input("Would you like to play again? (yes/y or no/n) ")