title: Accessing to a nonlocal variable by the following limitations
body: <p>I am trying to figure out a situation in  a exercise in Python<Br>
  The question is:</p>
  
  <p>Define two functions:   </p>
  
  <ul>
  <li>p: prints the value of a variable</li>
  <li>q: increments the variable</li>
  <li>Initial value of the variable is 0<br></li>
  </ul>
  
  <p>Limitations:<Br></p>
  
  <ul>
  <li>Variable is not located in the global environment, and the only way
  to change it is by invoking q()</li>
  <li>The only bindings introduced to global environment by the code are for p and q.</li>
  </ul>
  
  <p>The following code will describe the situation:</p>
  
  <pre><code># &gt;&gt;&gt; p()
  # 0
  # &gt;&gt;&gt; q()
  # &gt;&gt;&gt; q()
  # &gt;&gt;&gt; p()
  # 2
  # &gt;&gt;&gt; print([k for k,v in globals().items() if v==2]) 
  ## checks that a variable with the value ‘2’ does not exist in the global environment.
  # [] 
  </code></pre>
  
  <p>I would like to get some suggestions how should I solve it.<br>
  Thanks.</p>