title: CGPA Calc Python
body: <p>Help me please. im tryning to do a CGPA calculator. but someonething just goes wrong and i couldn't find the answer :'( i get this error message saying:</p>
  
  <pre><code> Traceback (most recent call last):
        file "cgpa.py", line 60 in 7
             count_sem, total_gpa, credit = input_user().
        file "cgpa.py", line 53, in input_user
             total_gpa=total_gpa + gpa
   unboudndlocalerror:local variable "gpa" reference before assignment
  </code></pre>
  
  <p>is there something wrong with my coding or the format somehow? i expect it to display funcion cgpa when the user press 1 for the menu. and the looping should end when the user enter finish then goes to the menu.</p>
  
  <pre><code>def menu(): 
  
   print "\n\n----CGPA MENU----\nChoose the option below:\n" 
   print "Enter 1 - Total CGPA"   print "Enter 2 - Total semester"  
   print "Enter 3 - Target Next GPA (if CGPA &lt; 3.0)"
   print "Enter 4 - EXIT "    user_menu = raw_input ("Option: ")
      return user_menu      
  
  def cgpa(a,b):
       average = a/b      
  
       return average
  
  def input_user(): 
       while True:
              count_sem = 0
              total_gpa = 0
              credit = 0
  
              print "\n~To STOP enter finish~"
  
              user1 = raw_input ("Enter GPA: ") 
              if user1 == "finish":           break
              try:
                      gpa = float (user1) 
              except:
                      print "Invalid number"
                      continue
  
              user2 = raw_input ("Semester: ")
              try:
                      sem = int(user2)
              except:
                      print "Invalid number"
                      continue        
  
              user3 = raw_input ("Enter total credit hour: ")
              try: 
                      hour =    int(user3)
              except:
                      print "Invalid number"
                      continue
  
              count_sem = count_sem + 1
              total_gpa = total_gpa + gpa
              credit =    credit + hour
  
          return count_sem, total_gpa, credit     
  
   while True:    
               count_sem, total_gpa, credit = input_user ()   
               user_menu = menu ()
  
               if user_menu == 1:
                       cgpa2 = cgpa (total_gpa,count_sem) 
                       print "Total CGPA: %.2f" % cgpa2
  
              elif user_menu == 2: 
                      print "22222@"
               print "DONE"
  </code></pre>