title: Function is able to access some global variables but not the others
body: <p><a href="https://i.stack.imgur.com/sFHuq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sFHuq.png" alt="enter image description here" /></a></p>
  <p>In the above piece of code, I have 5 different variables, all declared globally. But as you can see, continuePlaying (wrong naming convention, I know) is greyed out because it can't be accessed. But what I don't understand is that the other variables can be accessed. Why is that? And do I need to put a &quot;global variable_name&quot; line everytime before I use a global variable? Like in the &quot;scores&quot; function below.</p>
  <p>Below is the full code if needed:</p>
  <pre><code>import random 
  from art import logo
  
  cards = [11,2,3,4,5,6,7,8,9,10,10,10,10] player_cards = []
  casino_cards = [] player_score = 0 casino_score = 0
  
  def initial_draw():
      player_cards.append(cards[random.randint(0,12)])
      player_cards.append(cards[random.randint(0,12)])
      casino_cards.append(cards[random.randint(0,12)])
      casino_cards.append(cards[random.randint(0,12)])
      print(f&quot;Your cards are:\n{player_cards}&quot;)
      print(f&quot;Casino's cards are:\n[{casino_cards[0]}, ]&quot;)
      check_blackjack()
  
  def player_draw():
      player_cards.append(cards[random.randint(0,12)])
      print(f&quot;Your cards are:\n{player_cards}&quot;)
      print(f&quot;Casino's cards are:\n[{casino_cards[0]}, ]&quot;)
      check_score_player()
  
  def casino_draw():
      casino_cards.append(cards[random.randint(0,12)])
      print(f&quot;Your cards are:\n{player_cards}&quot;)
      print(f&quot;Casino's cards are:\n{casino_cards}&quot;)
  
  def casino_turn():
      while sum(casino_cards) &lt; 17:
          casino_draw()
          if sum(casino_cards) &gt; 21:
              game_end(&quot;player&quot;) 
  
  def scores():
      global player_score
      player_score = sum(player_cards)
      global casino_score 
      casino_score = sum(casino_cards)
  
  def check_blackjack():
      if sum(player_cards) == 21 and sum(casino_cards) == 21:
           game_end(&quot;draw&quot;)
      elif sum(player_cards) == 21:
          game_end(&quot;player&quot;)
      elif sum(casino_cards) == 21:
          game_end(&quot;casino&quot;)
          
  
  def check_score_player():
      if sum(player_cards) &gt; 21:
          game_end(&quot;casino&quot;)
  
  def final_check():
      scores()
      if (21 - player_score) &lt; (21 - casino_score):
          game_end(&quot;player&quot;)
      elif (21 - casino_score) &lt; (21 - player_score):
          game_end(&quot;casino&quot;)
      elif (21 - casino_score) == (21 - player_score):
          game_end(&quot;draw&quot;)
  
  def game_end(winner):
      scores()
      if winner == &quot;player&quot;:
          print(f&quot;Player won! Player's score: {player_score}\nCasino's score: {casino_score}&quot;)
          print(f&quot;Your cards were:\n{player_cards}&quot;)
          print(f&quot;Casino's cards were:\n{casino_cards}&quot;)
      elif winner == &quot;casino&quot;:
          print(f&quot;Player lost! Player's score: {player_score}\nCasino's score: {casino_score}&quot;)
          print(f&quot;Your cards were:\n{player_cards}&quot;)
          print(f&quot;Casino's cards were:\n{casino_cards}&quot;)
      elif winner == &quot;draw&quot;:
          print(f&quot;It was a draw! Player's score: {player_score}\nCasino's score: {casino_score}&quot;)
          print(f&quot;Your cards were:\n{player_cards}&quot;)
          print(f&quot;Casino's cards were:\n{casino_cards}&quot;)
      if input(&quot;Do you want to play again? \&quot;y\&quot; or \&quot;n\&quot;: &quot;).lower()== &quot;y&quot;:
          continuePlaying = True
      else:
          continuePlaying = False
      player_cards = []
      casino_cards = []
      player_score = 0
      casino_score = 0
  
  print(logo) 
  continuePlaying = True 
  while continuePlaying:
      initial_draw()
      if input(&quot;Do you want to draw another card? \&quot;y\&quot; or \&quot;n\&quot;: &quot;).lower()== &quot;y&quot;:
          wants_to_draw = True
      else:
          wants_to_draw = False
      while wants_to_draw:
          player_draw()
          if input(&quot;Do you want to draw another card? \&quot;y\&quot; or \&quot;n\&quot;: &quot;).lower()== &quot;n&quot;:
              wants_to_draw = False
      print(f&quot;Casino's cards are:\n{casino_cards}&quot;)
      casino_turn()
      final_check()
  </code></pre>