Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

put on hold as off-topic by Ffisegydd, Zero Piraeus, Antti Haapala, Kevin, Martijn Pieters 18 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Ffisegydd, Zero Piraeus, Antti Haapala, Kevin, Martijn Pieters
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
What errors are you getting? –  Kevin 18 hours ago
    
list index out of range when i input 1, When i input 2 it says there no operand for that int –  will the randomer price 15 hours ago
    
hmm... What do your text files look like? –  Kevin 15 hours ago
    
brief overview:a name,1score,2score,3score. all like that after the colon –  will the randomer price 15 hours ago
1  
Can you please edit the question to include the additional information? –  Wayne Conrad 15 hours ago

Browse other questions tagged or ask your own question.