lundi 30 mars 2020

Python exam grader marking a question wrong when its right

So I have this code that's supposed to grade student files, and everything works fine on student 1 However, when student 2 gets graded it's not displaying that he gets a 100% it says the answer they put (which is A) is wrong then it puts the correct answer (which is A) and it's marking his test as a 95% what am I doing wrong?

    total= 0
    for i in range(1, (minLen)+1):
        if student_lines[i] == answer_lines[i]:
            total += 1

            percentage= int((total/minLen)*100)
    print(" ")
    print("You scored", str(percentage) + "% on the exam.")
    print(" ")
    if percentage >= 93:
        print("You earned the letter grade A")
    elif percentage >= 90 and percentage < 93:
        print("You earned the letter grade A-")
    elif percentage >= 87 and percentage < 90:
        print("You earned the letter grade B+")
    elif percentage >= 83 and percentage < 87:
        print("You earned the letter grade B")
    elif percentage >= 80 and percentage < 83:
        print("You earned the letter grade B-")
    elif percentage >= 77 and percentage < 80:
        print("You earned the letter grade C+")
    elif percentage >= 73 and percentage < 77:
        print("You earned the letter grade C")
    elif percentage >= 70 and percentage < 73:
        print("You earned the letter grade C-")
    elif percentage >= 67 and percentage < 70:
        print("You earned the letter grade D+")
    elif percentage >= 60 and percentage < 67:
        print("You earned the letter grade D")
    elif percentage < 60:
        print("You earned the letter grade F")

    print(" ")
    if total < 100:
        print("You missed the following questions:")
        print(" ")
        print("Qn#\tYour Answer\tCorrect Answer")
        for i in range(1, (minLen)+1):
            if student_lines[i] != answer_lines[i]:
                incorrect_list= list(student_lines[i].split(','))
                correct_list= list(answer_lines[i].split(','))
                print(incorrect_list[0] + ".", "\t    ", incorrect_list[1].replace("\n", ""), "\t\t   ", correct_list[1].replace("\n",""))
    if total == 100:
        print("Congratulations you got all the questions correct")```


Aucun commentaire:

Enregistrer un commentaire