title: Avoid using global without confusing new programming students in Python?
body: <p>I've been teaching 8th-9th graders basic computer programming for two weeks, and yesterday I tried to show them how they could make real simple text-adventure games in Python.</p>
  
  <p>Scenes are functions, (e.g <code>dragons_cave()</code>) which consist of some print statements and then a call to <code>input()</code>, asking the player where they want to go next, which then gets passed to <code>globals()</code> to find the appropriate function and then called. I know it's not ideal (at what point would the huge chain of functions start becoming a problem?) but, of what crossed my mind, it seems to be the simplest for them while involving only a little handwaving.</p>
  
  <p>My problem is with global state — ex. the player gets a key in one scene and only then can they unlock the gate in another scene. When I have global immutables like strings or booleans, Python wants me to use the <code>global</code> keyword at the beginning of the function.</p>
  
  <pre><code>global hasKey
  hasKey = True
  </code></pre>
  
  <p>I'm pretty okay with that, but I have a vague sense (picked up from Stackoverflow among other places on the Internet) that <code>global</code> is frowned upon and always has a superior counterpart. I could have a global dictionary or wrap everything in a class, but I'm not sure if I could defend those options clearly to my kids (who are still thinking through the implications of variables).</p>
  
  <p>Whatever I use, I want to be able to explain straightforwardly to my kids why we do it this way and why doing it this way is necessary. <code>global</code> seems to have both these properties, but is it bad?</p>