
Untitled
By: a guest on
May 1st, 2012 | syntax:
Python | size: 1.29 KB | hits: 29 | expires: Never
#Black jack game
#python 2.7
import random
cards = []
def game():
print "You have " + str(len(cards)) + " card(s)"
print "Current cards:"
print cards
print "1 - Hit\n2 - Stand"
usrInput = int(raw_input("?"))
if usrInput == 1:
cards.append(random.randrange(1,12))
print cards
if sum(cards) == 21:
print "You win!"
elif sum(cards) > 21:
print "You lose :("
elif sum(cards) < 21:
game()
else:
dealerSum = random.randrange(17, 22)
print "The dealer had: " + str(dealerSum)
print "You had: " + str(sum(cards))
if sum(cards) > dealerSum and not sum(cards) == 21:
print "You win!"
elif sum(cards) == dealerSum:
print "You tie!"
elif sum(cards) < dealerSum:
print "You lose :("
def main():
isQuit = False
while isQuit == False:
print "=================="
print "1 - Play\n2 - Quit"
try:
usrInput = int(raw_input("?"))
if usrInput == 2:
isQuit = True
elif usrInput == 1:
del cards[:]
game()
except ValueError:
print "Invalid Input"
main()