title: Sorting data from highest to lowest, and sorting averages by highest to lowest in Python from text files
body: <p>I need to create a program that you type in which class you want and what you want it sorted in (alphabetically, averages and highest to lowest) and it prints it when run. This is my code so far I have managed to do the alphabetical part but am struggling on the average and the highest to lowest part.</p>
  
  <p>Here is part of my code so far:</p>
  
  <hr>
  
  <pre><code>def sortchoice():
        sort = input("What class do you want to sort? 1, 2, 3? if you dont want to sort any, type: 0  ")
  
  if sort == "1":  
  
      def viewclasschoice1():
          viewclass = input("choose either alphabetically (type a), average (type b) or highest (type c)?")
          if viewclass == "a":
              with open('Class 1.txt', 'r') as r:
                  for line in sorted(r):
                      print(line, end='')
  
  
          elif viewclass == "b":
               with open('Class 1.txt', 'r') as r:
                  for line in sorted(r):
                      print(line, end='')
  
  
          elif viewclass == "c":
              def score(line):
                  return int(line.split(',')[1])
  
              with open('Class 1.txt', 'r') as r:
                  for line in sorted(r, key=score, reverse=True):
                      print(line)    
  
          else:
              viewclasschoice1()
      viewclasschoice1()    
  </code></pre>