# Simple Blackjack System # Chad Haynes # 5/12/2003 print 'Welcome to my simple blackjack system' print 'Please enter the cards dealt to you' print 'Card values must be one of 2,3,4,5,6,7,8,9,10,J,Q,K,A' print 'Aces will always be 11\n' # Input information from user card1 = raw_input('Enter first card: ') # determine value of first card if card1 == 'A': total = 11 elif card1 == 'K' or card1 == 'Q' or card1 == 'J': total = 10 elif 1 < int(card1) <= 10: total = int(card1) else: raise ValueError, 'Error entering card 1' # raise an exception # Input second card and add value to first card2 = raw_input('Enter second card: ') if card2 == 'A': total += 11 # shorthand for total = total + 11 elif card2 == 'K' or card2 == 'Q' or card2 == 'J': total += 10 elif 1 < int(card2) <= 10: total += int(card2) else: raise ValueError, 'Error entering card 2' # raise an exception # Display entered information print "You entered " + card1 + " and " + card2 # Input dealers visible card dealer = raw_input('Enter dealers top card: ') if dealer == 'A': dealerValue = 11 elif dealer == 'K' or dealer == 'Q' or dealer == 'J': dealerValue = 10 elif 1 < int(dealer) <= 10: dealerValue = int(dealer) else: raise ValueError, 'Error entering dealer card' # if dealer is below 7 or your total is 17 or above you should stand # otherwise get another card if dealerValue < 7 or total >= 17: print 'Stand' else: print 'Hit' card3 = raw_input('Enter third card: ') if card3 == 'A': total += 11 elif card3 == 'K' or card3 == 'Q' or card3 == 'J': total += 10 elif 1 < int(card3) <= 10: total += int(card3) else: raise ValueError, 'Error entering third card' # check if busted if total > 21: print '%i - Busted' % (total) else: print 'Current total is: %i' % (total)