title: UnboundLocalError: local variable 'Score' referenced before assignment
body: <pre><code>import time
  from random import randint
  import sys
  import random
  Level = 0
  ONE = 10
  TWO = 20
  THREE = 60
  FOUR = 100
  FIVE = 150
  QN = 0
  TEN = 10
  Zero = 0
  Chances = 5
  Score = 0
  Name = input("What is your name? \n").title()
  time.sleep(1)
  class_name = input("What class are you in? \n").upper()
  time.sleep(1)
  print("Welcome!\nTo the Ten Question Quiz {}!!".format(Name))
  time.sleep(1)
  operation = ['+','-','*']   #holds all of the opperators
  RO = random.choice(operation)#chooses a random operator
  def Quiz():
      RoG = input(Name+" Please type 'rules' to view the rules or Press 'ANY' key to Continue\n*********************************************************************************************************\n")
      if RoG == "rules":
          time.sleep(1)
          print("*********************************************************************************************************")
          print("*RULES/HOW TO PLAY* \nThere will be 10 Questions for you to answer \nthere WILL be a timer, total time taken to finish the quiz \nYou will be able to choose the Level from 1, 2, 3\n1 = Very Easy, 2 = Easy, 3 = Medium, 4 = Hard, 5 = Very Hard \nYou will only have '5' chances to answer, 'ALL' The 10 Questions.")
          input("Press 'ANY' key to Return to the previous page\n*********************************************************************************************************")
          Quiz()
      else:
          LV = input("Please Choose Your Level From (1, 2, 3, 4, 5)\n")
          if LV == "1":
              Level = ONE
          elif LV == "2":
              Level = TWO
          elif LV == "3":
              Level = THREE
          elif LV == "4":
              Level = FOUR
          elif LV == "5":
              Level = FIVE
          def Timer():
              start_time = time.time()
              def Q1():  
                  global Chances
                  while Chances &gt; Zero:
                      global QN
                      QN = QN+1
                      if str(QN) == "10":
                          time.sleep(1)
                          print("You have Finished The Ten Question Quiz {} !!".format(Name))
                          time.sleep(1)
                          end_time = time.time()
                          print("Total time taken was %g seconds." % (end_time - start_time))
                          print("Your Score is {} /10".format(Score))
                          Class_name = class_name + ".txt"    #adds '.txt' to the end of the file so it can be used to create a file under the name a user specifies
                          file = open(Class_name , 'a')   #opens the file in 'append' mode so you don't delete all the information
                          name = (Name)
                          file.write(str(name + " " + class_name + ", Your score is: " )) #writes the information to the file
                          file.write(str(Score))
                          file.write("/10 Level: ")
                          file.write(str(LV))
                          file.write(", Total time taken was %g seconds." % (end_time - start_time))
                          file.write('\n')
                          file.close()    #safely closes the file to save the information
                          viewscore = input("Do you wish to view previous results for your class:(yes/no) \n").lower()
                          if viewscore == "yes".lower():
                              f = open(Class_name, 'r')
                              file_contents = f.read()
                              print (file_contents)
                              f.close()
                              if input("Press 'Y' to exit \nor press any key to start again.").lower() == "y":
                                  sys.exit()
                              else:
                                  ex = input("")
                                  Quiz()
                          elif viewscore != "yes".lower():
                              if input("Press 'Y' to exit \nor press any key to start again.").lower() == "y":
                                  sys.exit()
                              else:
                                  ex = input("")
                                  Quiz()
                      else:
                          print("Starting Question {}".format(QN))
                          Ran1 = randint(1,Level)
                          Ran11 = randint(1,Level)
                          time.sleep(1)
                          RO = random.choice(operation)    #chooses a random operator
                          Answer1=int(eval(str(Ran1) + RO + str(Ran11)))
                          print ("What is {} {} {}?".format(Ran1, RO, Ran11))
                          if input() == str(Answer1):
                              print("Thats the Correct Answer WELL DONE!")
                              Score = Score+1
                              print("*********************************************************************************************************")
                              Q1()
                          else:
                              Chances = Chances-1
                              print("Wrong!\nThats the wrong answer, you got {} Chance(s)".format(Chances))
                              print("*********************************************************************************************************")
                              Q1()
              Q1()
          Timer()
  Quiz()
  </code></pre>
  
  <p>I know that some of the variables set here are not needed, but I'll fix them in the future; all I want to know is how to fix this error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "N:/IMPORTANT/Assessment2222 - Copyc.py", line 105, in &lt;module&gt;
      Quiz()
    File "N:/IMPORTANT/Assessment2222 - Copyc.py", line 104, in Quiz
      Timer()
    File "N:/IMPORTANT/Assessment2222 - Copyc.py", line 103, in Timer
      Q1()
    File "N:/IMPORTANT/Assessment2222 - Copyc.py", line 95, in Q1
      Score = Score+1
  UnboundLocalError: local variable 'Score' referenced before assignment
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I have tried <code>global Score</code> but then it says;</p>
  
  <pre><code>&gt;&gt;&gt; 
  Warning (from warnings module):
    File "N:/IMPORTANT/Assessment2222 - Copyc.py", line 95
      global Score
  SyntaxWarning: name 'Score' is used prior to global declaration
  </code></pre>
  
  <p>So now I am out of options.</p>