title: Accessing a variable from a defined function in a while loop
body: <p>I have code that looks similar to this</p>
  
  <pre><code>v = '0'
  
  def program():
      x = input('1 or 2 ')
      if x == '1':
          print('it is 1')
          v = '1'
      elif x == '2':
          print('it is 2')
          v = '2'
  
  while True:
      program()
      print(v)
  </code></pre>
  
  <p>However, when I run this code the variable 'v' always prints out the default 0.
  Why isn't it giving me the variable I assigned it in the function?</p>