title: NameError: name 'x' is not defined Python
body: <p>I'm trying to get around this error but can't find a solution. Actually the code worked perfectly some time but suddendly started to drop the error:</p>
  <pre><code>&quot;NameError: name 'number_exit' is not defined&quot; 
  </code></pre>
  <p>And also:</p>
  <pre><code>&quot;NameError: name 'price_buy' is not defined&quot;
  </code></pre>
  <p>The code is generating a list of random numbers</p>
  <pre><code>import numpy as np
  
  # This function generates a list of numbers under certain rules
  def num_var_list():
      global number_list, number_exit, number_target
      number_list = []
      number_target = number_exit
      num_max_robot = (number_target * 20) / 100
      while num_max_robot &gt; 0:
          num_robot = np.random.randint(1,int(num_max_robot))
          if num_robot &gt; number_target:
                  number_list.append(number_target)
          else: 
              number_list.append(num_robot)
          number_target = number_target - number_target
      return number_list
          
  # This function generates a random number between a certain range
  def fun_price_buy():
      global price_buy
      price_buy = np.random.randint(50000,300000)
      return price_buy
  
  # This function generates a random number between a certain range
  def fun_mx_buy():
      global number_exit
      number_exit = np.random.randint(50, 150)
      return number_exit
  
  lista_number_list = []
  lista_price_buy = []
  lista_mx_buy = []
  
  # This loop append each function 50 times to a new list
  while len(lista_price_buy) &lt;= 50: 
      lista_number_list.append(num_var_list())
      lista_price_buy.append(fun_price_buy())
      lista_mx_buy.append(fun_mx_buy())
  </code></pre>
  <p>Actually, when <code>Python</code> doesn't drop the error, the code makes exactly what I want it to do. So I'm not sure how to adjust it to let it work without NameError warnings.</p>
  <p>Any help will be highly appreciated. Thank you!</p>