title: Python - Sorting file highest to lowest and alphabetically
body: <p>I have created an arithmetic code, that asks the user 10 questions, and then stores their name and score in a database e.g. <code>C:\class1.txt</code> and I'm now at the stage, where I should be able to sort the file containing the name and the score of multiple pupils from each individual class, in both highest to lowest (scores) and alphabetically. The program should ask a question at the end of the code, asking the teacher if they want it sorted alphabetically or highest to lowest by score. They should also be able to pick the class they want sorted, and it should be printed.</p>
  
  <p>I am asking for guidance on this, I do not want to cheat, I am just now clueless at this stage; with a teacher that is useless.</p>
  
  <p>Thanks in advance      </p>
  
  <pre class="lang-py prettyprint-override"><code>import random
  USER_SCORE = 0
  questions = 0
  classnumber = ("1","2","3")
  name1= input("Enter Your Username: ")
  print("Hello, " + name1)
  print(" Welcome to the Arithmetic Quiz")
  
  classno = input("What class are you in?")
  while classno not in classnumber:
      print("Enter a valid class")
      print("ENTER ONLY THE NUMBER n\ 1 n\ 2 n\3")
      classno=input("What class are you in?")
  
  while questions &lt;10:
      for i in range(10):
          num1=random.randint(1,10)
          num2=random.randint(1,10)
          on=random.choice("*-+")
          multiply=num1*num2
          subtract=num1-num2
          addition=num1+num2
  
          if on == "-": #If "-" or subtract is randomly picked.
              print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
              questions+=1
              print(" Question" ,questions, "/10")
              uinput=input(str(num1)+" - "+str(num2))
              if uinput == str(subtract):
                  USER_SCORE+=1
                  print("     Correct, your USER_SCORE is: " ,USER_SCORE,)
              else:
                  print ("    Incorrect, the answer is: " +str(subtract))
                  USER_SCORE+=0
  
          if on == "+":
              print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
              questions+=1
              print(" Question",questions, "/10")
              uinput=input(str(num1)+" + "+str(num2))
              if uinput == str(addition):
                  USER_SCORE+=1
                  print("  Correct, your USER_SCORE is: ",USER_SCORE,)
              else:
                  print("  Incorrect, the answer is: " +str(addition))
                  USER_SCORE+=0
  
          if on == "*":
              print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
              questions+=1
              print(" Question",questions, "/10")
              uinput=input(str(num1)+" * "+str(num2))
              if uinput == str(multiply):
                  USER_SCORE+=1
                  print("  Correct, your USER_SCORE is: " ,USER_SCORE,)
              else:
                  print("  Incorrect, the answer is: " +str(multiply))
                  USER_SCORE+=0
  
  if USER_SCORE &gt;9:
      print("Well done," ,name1, "your score is" ,USER_SCORE, "/10")
  else:
   print(name1," your score is " ,USER_SCORE, "/10")
  
  def no1():
       with open("no1.txt", 'a')as file:
           file.write(str(name1)+" achieved a score of:  "+str(USER_SCORE)+"/10 \n")
  def no2():
       with open("no2.txt", 'a')as file:
           file.write(str(name1)+" achieved a score of "+str(USER_SCORE)+"/10 \n")
  def no3():
       with open("no3.txt", 'a')as file:
           file.write(str(name1)+" achieved a score of "+str(USER_SCORE)+"/10 \n")
  if classno=="1":
      no1()
  if classno=="2":
      no2()
  if classno=="3":
      no3()
  </code></pre>