title: Trying To Develop a Scoring System for Blackjack Game
body: <p>so I'm trying to make a scoring system using my current code for blackjack. The game is versus the computer and a player and the rules are a bit different , but that has all been setup. I need to purpose the code for scoring both player and computer's cards. I also should make it so an ace is set to be the value of 1, if to avoid busting. I was thinking of doing so as cards are drawn, but I'm not entirely sure. I tried cross class variables and I didn't find much success. Maybe I could fuse the player and deck classes? </p>
  
  <p>Anyways, here is what I have, I'll provide any more information you need and there should be fairly thorough comments. </p>
  
  <pre class="lang-py prettyprint-override"><code># This is a game of blackjack versus a computer.
  # ------------------------------------------------------------------------------------------------------
  # importing necessary files
  import random
  
  # A couple global variables for any necessary repeats and scoring.
  RepeatCardChoice = 0
  YourScore = 0
  ComputerScore = 0
  HitCount = 0  # The amount of times the player hits. Used for showing cards.
  
  # Our deck itself.
  class Card:  # This is for developing the cards in the first place.
      def __init__(self, suit, rank):
          self.suit = suit
          self.rank = rank
  
      def show(self):
          print(str(self.rank) + str(self.suit))
  
  class Deck:  # This is for deck behaviors and creating a deck.
      def __init__(self):
          self.cards = []
          self.Cards()
  
      def Cards(self):
          for suit in ["S", "C", "D", "H"]:  # S = Spades, C = Clubs, D = Diamonds, and H = Hearts
              for rank in range(1, 14):
                  value = rank
                  if rank == 1:
                      rank = 'A'  # Makes all 1 values = to ace.
                  elif rank == 11:
                      rank = 'J'  # Makes all 11 values = to jack or j.
                  elif rank == 12:
                      rank = 'Q'  # Makes all 12 values = to queen or Q.
                  elif rank == 13:
                      rank = 'K'  # Makes all 13 values = to king or K.
                  if rank == (11) or (12) or (13):
                      value = 10
                  elif rank == 1:
                      value == 11
                  self.value = value
                  self.cards.append(Card(suit, rank))
  
      def show(self):  # Shows each card individually.
          for card in self.cards:
              card.show()  # Really just reusing another function to display results.
  
      def shuffle(self):
          random.shuffle(self.cards)
  
      def drawCard(self):
          return self.cards.pop()
  
  class Player:  # This class is for player behaviors such as drawing and showing your hand.
      def __init__(self, name):
          self.name = name  # Allows the player to choose their name.
          self.hand = []  # Assigns their cards to a list, to be saved.
          self.Deck = Deck()
  
      def draw(self, deck, CardCount):  # How the player draws one card at a time. It wasn't necessary to allow more.
          count = 0
          while count != CardCount:
              count += 1
              self.hand.append(deck.drawCard())
          return self
  
      def showHand(self, showCount):  # Shows each card in the player's hand.
          count = 0  # A counter is used to limit how much is drawn.
          for card in self.hand:  # This is so "card" doesn't stay an unresolved reference.
              if count == showCount:
                  return
              count += 1
              card.show()
  
  # Below is where we apply the classes and play the game. The computer will operate without input, unlike the player.
  # Here is the deck.
  deck = Deck()
  deck.shuffle()  # Shuffling the deck in preparation.
  
  PlayerName = str(input('What is your name?'))  # Just so the player can choose their name.
  
  # Setting up the players.
  Computer = Player("The Computer")
  You = Player(PlayerName)
  
  # Giving both players their hand to start off with.
  Computer.draw(deck, 2)
  You.draw(deck, 2)
  
  # Here is where one card in each hand is shown.
  print('You are showing:')
  You.showHand(1)
  print('The computer is showing:')
  Computer.showHand(1)
  
  # Here is where you decide to hit or stand.
  while RepeatCardChoice == 0:
      CardChoice = str(input('Hit (H) or Stand (S)?'))
      if CardChoice == 'H':
          You.draw(deck, 1)
          HitCount += 1
          You.showHand(1+HitCount)
          RepeatCardChoice = 0  # This is so the player can keep deciding whether they still want to hit?
      elif CardChoice == 'S':
          RepeatCardChoice = 21  # Get it, because the winning score in blackjack is 21?
          HitCount = 0
      else:
          RepeatCardChoice = 0
      # Here is where we check your score.
      if YourScore &gt; 21:
          exit('You busted and the computer wins!')
      elif YourScore == 21:
          exit('Blackjack, you win!')
  
  # Here is where the computer hits or stands.
  while ComputerScore &lt;= 17:
      Computer.draw(deck, 1)
      HitCount +=1
      Computer.showHand(1+HitCount)
  if ComputerScore&gt;21:
      exit('The computer busted and you win!')
  elif ComputerScore == 21:
      exit('Blackjack, the computer wins!')
  
  # Here is where we compare the scores to decide the winner.
  if ComputerScore &gt; YourScore:
      exit('The computer wins!')
  elif YourScore &gt; ComputerScore:
      exit('You win!')
  elif ComputerScore == YourScore:
      exit('You tied')
  </code></pre>
  
  <p>The output shouldn't provide any errors if the scoring system is successful, and I setup some variables that I might use to assign the score, however this can be changed as needed. Here is the output anyways.</p>
  
  <pre class="lang-py prettyprint-override"><code>What is your name?Sample
  You are showing:
  KC
  The computer is showing:
  JS
  Hit (H) or Stand (S)?H
  KC
  8S
  Hit (H) or Stand (S)?S
  JS
  ...
  Traceback (most recent call last):
    File "Censored", line 119, in &lt;module&gt;
      Computer.draw(deck, 1)
    File "Censored", line 66, in draw
      self.hand.append(deck.drawCard())
    File "Censored", line 54, in drawCard
      return self.cards.pop()
  IndexError: pop from empty list
  </code></pre>
  
  <p>Essentially, what is happening is that the computer hits infinitely due to a lack of scoring, until there is nothing left to draw, this is after you stand. I skipped a lot of lines in the output, as they're just a bunch of cards getting drawn.</p>