title: def function not running correctly
body: <p>Please don't be too mean I have only started to use Python and wanted to try and complete a calculator that can use brackets and BIDMAS. I am currently at the stage of starting the part about brackets but when I run my program it will not run my def functions properly.</p>
  
  <pre><code>import time
  import os
  import random
  import sys
  
  print("=======================")
  print("Use ^ for the power of")
  print("Use + for adding")
  print("Use - for subtracting")
  print("Use * for multiplying")
  print("Use / for dividing")
  print("Use % for a percentage")
  print("DON'T USE SPACES!")
  print("=======================\n\n")
  
  uilist = ""
  uilength = ""
  user_input = ""
  
  def to_the_power_of(a):
      postion_n1 = a.index("^")
      postion_n2 = postion_n1 + 1
      n1 = int(a[:postion_n1])
      n2 = int(a[postion_n2:])
      total = n1**n2
      sign = "^"
  
  def subtracting(a):
      postion_n1 = a.index("-")
      postion_n2 = postion_n1 + 1
      n1 = int(a[:postion_n1])
      n2 = int(a[postion_n2:])
      total = n1-n2
      sign = "-"
  
  def adding(a):
      postion_n1 = a.index("+")
      postion_n2 = postion_n1 + 1
      n1 = int(a[:postion_n1])
      n2 = int(a[postion_n2:])
      total = n1+n2
      sign = "+"
  
  def multiplying(a):
      postion_n1 = a.index("*")
      postion_n2 = postion_n1 + 1
      n1 = int(a[:postion_n1])
      n2 = int(a[postion_n2:])
      total = n1*n2
      sign = "x"
  
  def dividing(a):
      postion_n1 = a.index("/")
      postion_n2 = postion_n1 + 1
      n1 = int(a[:postion_n1])
      n2 = int(a[postion_n2:])
      total = n1/n2
      sign = "/"
  
  def percentage(a):
      postion_n1 = a.index("%")
      postion_n2 = postion_n1 + 1
      n1 = int(a[:postion_n1])
      n2 = int(a[postion_n2:])
      total = (n1*n2)/100
      sign = "%"
  
  def calculate(ab):
      uilength = len(ab)
      uilist = list(ab)
      if "^" in uilist:
          to_the_power_of(answer_1)
  
      elif "+" in uilist:
          adding(answer_1)
  
      elif "-" in uilist:
          subtracting(answer_1)
  
      elif "*" in uilist:
          multiplying(answer_1)
  
      elif "/" in uilist:
          dividing(answer_1)
  
      elif "%" in uilist:
          percentage(answer_1)
  
      else:
          print("Please eneter a valid calculation!")
  
  while True:
      user_input = input("Write your calculation: ")
  
  
      answer_1 = user_input
      calculate(user_input)
  
      print(user_input,"=",total)
  
      exit_cal = input("Would you like to exit or make a now calculation?").lower()
      exit_list = ["exit","quit","leave","404"]
      if exit_cal in exit_list:
          sys.exit()
  </code></pre>
  
  <p>This is the error I get</p>
  
  <pre><code>=======================
  Use ^ for the power of
  Use + for adding
  Use - for subtracting
  Use * for multiplying
  Use / for dividing
  Use % for a percentage
  DON'T USE SPACES!
  =======================
  
  
  Write your calculation: 12*4
  Traceback (most recent call last):
    File "C:\Users\Max\Desktop\Python Scripts\Calculator.py", line 99, in &lt;module&gt;
      print(user_input,"=",total)
  NameError: name 'total' is not defined
  </code></pre>
  
  <p>Any help will be greatly appreciated!</p>