title: Python undefined variable issue
body: <p>During python programming, i met an undefined error.</p>
  <p>The error is about 'flag' variable and i can use it in the above print sentence without any error.</p>
  <p>Why the error occur only for index of array?</p>
  <p>If you have any ideas, please share it for me.</p>
  <p>Thank you for your interest.</p>
  <pre><code>class Solution:
      def rob(self, nums: List[int]) -&gt; int:
          global memo
          
          memo = [[0 for j in range(len(nums))] for i in range(2)]
          flag = 0
          #print(&quot;===========================&quot;)
          def dp(i : int) -&gt; int:
              global flag
              
              if i &gt;= len(nums):
                  #print(i,&quot;return 0&quot;)
                  return 0
  
              if i == 1:
                  flag = 1
                  #print(str(i) + &quot; : &quot; + str(globals), memo)
  
              if memo[flag][i] is not 0: # &lt;= undefined error occur because of flag
                  #print(i,&quot;*&quot;,memo)
                  return memo[i]
              memo[i] = max(dp(i+1), (dp(i+2) + nums[i]))
              if i is len(nums) - 1 and i is not 0:
                  result = nums[i] * flag
                  flag = 0
                  #print(str(i) + &quot; ! &quot; , result)
                  return result
              #print(i,&quot;-&quot;,memo)
              return memo[i]
          return max(dp(0), dp(1))
  </code></pre>
  <pre><code>NameError: name 'flag' is not defined. Did you mean: 'flags'?
      if memo[flag][i] is not 0:
  Line 21 in dp (Solution.py)
      return max(dp(0), dp(1))
  Line 37 in rob (Solution.py)
      ret = Solution().rob(param_1)
  Line 57 in _driver (Solution.py)
      _driver()
  Line 68 in &lt;module&gt; (Solution.py)
    if i is len(nums) - 1 and i is not 0:
    if memo[flag][i] is not 0:
  </code></pre>