title: Change the value of Global Variable in Python3
body: <p>How can I modify a global variable in the main function? I set a global variable <code>ADDITION</code> and modify it in a function. Then, I try to modify it in <code>main</code>, but it seems like I failed.</p>
  
  <pre><code>ADDITION = 0
  
  def add(a, b):
      global ADDITION
      ADDITION = ADDITION + 1
      return a+b
  
  def fib_classic(n):
      if(n &lt;= 1):
              return n
  
      else:
              return add(fib_classic(n-2) , fib_classic(n-1))
  
  
  def fib_closed(n):
      fib = (math.pow(1+math.sqrt(5),n) - (1-math.pow(math.sqrt(5),n)))/(math.pow(2,n)*math.sqrt(5))
      return math.floor(fib)
  
  
  def fib_classic(n):
      if(n &lt;= 1):
              return n
  
      else:
              return add(fib_classic(n-2) , fib_classic(n-1))
  
  
  def fib_loop(n):
      a = 0
      b = 1
  
      if(n &lt;= 1):
              return n
  
      else:
              for i in range(0, n-1):
                      c = b
                      b = add(a, b)
                      a = c
              return b
  
  
  def fib_mem(n):
      global FIB_DIC
      if(n in FIB_DIC):
              return FIB_DIC[n]
  
      else:
              if(n &lt;= 1):
                      FIB_DIC[n] = n
  
              else:
                      FIB_DIC[n] = add(fib_mem(n-1), fib_mem(n-2))
  
              return FIB_DIC[n]
  
  def main():
  
      for i in range(0,36):
              global ADDITION
              print("Computing the {0}th Fibonacci Number:".format(i))
              print("The closed form finds:", end=" "); print(fib_closed(i))
              print("The recursive definition finds:", end=" "); print(fib_classic(i))
              print("Additions needed for recursive definition:", end=" "); print(ADDITION)
              ADDITIION = 0
              print(ADDITION) # not 0
              print("The loop definition finds:", end=" "); print(fib_loop(i))
              print("Additions needed for loop definition:", end=" "); print(ADDITION)
              ADDITION = 0
              print("The memoization definition finds:", end=" "); print(fib_mem(i))
              print("Additions needed for memoization definition:", end=" "); print(ADDITION)
              print("--------------------")
  </code></pre>