I'm doing a controlled assessment and need to do a sorting script. When I run the program all I get is errors. I have files that look like this:
kevin,2,6,8
susan,3,1,7
mike,9,4,8
john,1,5,10
Here Is My Code
import csv
import operator
proceed = True
while proceed:
print("Computing Trivia Quiz - Teachers Results Analysis")
print("=======================")
classno=int(input("Please enter a class no: "))
file = open("class%i.txt" %classno, "r")#opens the file that you chose in classno
csv1 = csv.reader(file, delimiter = ',')#read file and deletes commas
sort = sorted(csv1)
for i in range(0, len(sort)):
sort[i].append((int(sort[i][1]))) + ((int(sort[i][2]/int(len(sort[i]-1)))))
sort[i].append((max(sort[i][1:3])))#meant to make an average its the part with the problem
print ("""
1.Sorted by Name (with high score)
2.Sort by Highest score
3.Sort by Average score
4.Exit/Quit
5.Try another sort activity
""")
ans=input("What would you like to sort the list:")
print("\n")
if ans=="1":
sort = list(sorted(sort,key=operator.itemgetter(0),reverse=False))
for i in range( 0, len( sort) ):
print( "Name:",sort[i][0])#sorts results and prints them
elif ans=="2":
sort = list(sorted(sort,key=operator.itemgetter(1,2),reverse=True))
for i in range( 0, len( sort) ):
print( "Name:",sort[i][0], "Max:",sort[i][1], "Min:",sort[i][2])#sorts results and prints them
elif ans=="3":
sort = list(sorted(sort,key=operator.itemgetter(3),reverse=True))
for i in range( 0, len( sort) ):
print( "Name:",sort[i][0], "Average:",sort[i][3])#sorts results and prints them
elif ans=="4":
print("Goodbye")
proceed = False
elif ans!="":
print("Not a valid choice")
again = input("Press 5 to try another sort")
if again == '5':
print("Try another Sort ")
else:
break#It allows you to make another sort if you inputted the number 5
Can someone help me with my code.