title: Python: How to use named variables from one function in other functions
body: <p>I'm a newbie programmer trying to make a program, using Python 3.3.2, that has a <code>main()</code> function which calls <code>function1()</code>, then loops <code>function2()</code> and <code>function3()</code>.</p>
  
  <p>My code generally looks like this:</p>
  
  <pre><code>def function1():
      print("hello")
  
  def function2():
      name = input("Enter name: ")
  
  def function3():
      print(name)
  
  def main():
      function1()
      while True:
          funtion2()
          function3()
          if name == "":
              break
  
  main()
  </code></pre>
  
  <p>Currently, I get the following error when I run the program and enter a name:</p>
  
  <pre><code>NameError: global name 'name' is not defined
  </code></pre>
  
  <p>I understand that this is because <code>name</code> is only defined within <code>function2()</code>. How do I make it so that <code>name</code> is defined as a 'global name', or somehow be able to use it within <code>function3()</code> and <code>main()</code>.</p>
  
  <p>Thanks in advance.</p>