title: In my code i am getting a name error saying the name 'sort' is not defined
body: <pre><code>import csv
  import operator
  
  form = input('If you would like to view form 1 please enter "1".If you would like to view form 2 please enter "2" and If you would like to view form 3 please enter "3"')
  if form == "1":
     sort = input('If you would like the names sorted alphabetically enter "a".If you would like the scores sorted from highest to lowesr please enter "b" and If you would like the average scores sorted from highest to lowest please enter "c"')
  if sort == "a":
      readfile = csv.reader(open("Form1.csv"), delimiter=",")
      sortedfile = sorted(readfile, key=operator.itemgetter(0))
      file = open("Form1.csv", "a")
      for eachline in sortedfile:
          eachline.sort()
          print(eachline)
      file.close()
  if sort == 'b':
      file = open('Form1.csv')
      readfile = csv.reader(file)
      for line in readfile:
          integers = (line[0:4])
          integers.sort(reverse = True)
          print(integers)
  averages = []
  if sort == 'c':
      file = open('Form1.csv')
      readfile = csv.reader(file)
      for line in readfile:
          values = (line[2:4])
          values = list(map(int, values))
          average = (sum(values)/len(values))
          averages.append(average)
          averages.sort(reverse = True)
          print(averages)
  
  elif form == "2":
      sort = input('If you would like the names sorted alphabetically enter "a".If you would like the scores sorted from highest to lowesr please enter "b" and If you would like the average scores sorted from highest to lowest please enter "c"')
  if sort == "a":
      readfile = csv.reader(open("Form2.csv"), delimiter=",")
      sortedfile = sorted(readfile, key=operator.itemgetter(0))
      file = open("Form2.csv", "a")
      for eachline in sortedfile:
          eachline.sort()
          print(eachline)
      file.close()
  if sort == 'b':
      file = open('Form2.csv')
      readfile = csv.reader(file)
      for line in readfile:
          integers = (line[0:4])
          integers.sort(reverse = True)
          print(integers)
  averages = []
  if sort == 'c':
      file = open('Form2.csv')
      readfile = csv.reader(file)
      for line in readfile:
          values = (line[2:4])
          values = list(map(int, values))
          average = (sum(values)/len(values))
          averages.append(average)
          averages.sort(reverse = True)
          print(averages)
  
  elif form == "3":
      sort = input('If you would like the names sorted alphabetically enter "a".If you would like the scores sorted from highest to lowesr please enter "b" and If you would like the average scores sorted from highest to lowest please enter "c"')
  if sort == "a":
      readfile = csv.reader(open("Form3.csv"), delimiter=",")
      sortedfile = sorted(readfile, key=operator.itemgetter(0))
      file = open("Form3.csv", "a")
      for eachline in sortedfile:
          eachline.sort()
          print(eachline)
      file.close()
  if sort == 'b':
      file = open('Form3.csv')
      readfile = csv.reader(file)
      for line in readfile:
          integers = (line[0:4])
          integers.sort(reverse = True)
          print(integers)
  averages = []
  if sort == 'c':
      file = open('Form3.csv')
      readfile = csv.reader(file)
      for line in readfile:
          values = (line[2:4])
          values = list(map(int, values))
          average = (sum(values)/len(values))
          averages.append(average)
          averages.sort(reverse = True)
          print(averages)
  </code></pre>
  
  <p>Could you please tell me what i could do to solve this problem please.Thanks. I also have another problem when i give the response 1 to the first question and give the response a for the second question it prints out the names from all the from files however it is meant to input the names from form one only.</p>