What I am trying to do is read from a text file that has a list of names that corresponds to three grades. In the program the file is read and entered into one dictionary. From the dictionary I am to compare scores and print which is the highest, lowest, etc. I'm trying to use a for loop, but I keep running into several issues. This time I ran into error type 1 when I try to compile. What is the best way to compare dictionary values in a for loop? Any Suggestions?
Here is a same of the text file:
Brian,94,89,92 Rachel,100,90,65 Jon,67.5,95,100 Brit,0,78,80 Greg,65,100,78 Andrea,55.5,67,79
Here is my code so far:
def examMod ():
students = {}
infile = open("studentGrades.txt","r")
for aline in infile:
key, val1, val2, val3 = aline.split(',')
students[key] = float(val1), float(val2), float(val3)
for z in students.keys():
for x in students.items():
if students[1] > students[2] & students[1] > students[3]:
print("For %s test 1 is the highest scored." % z)
elif students[2] > students[1] & students[2] > students[3]:
print("For %s test 2 is the highest scored." % z)
elif students[3] > students[1] & students[3] > students[2]:
print("For %s test 2 is the highest scored." % z)
Aucun commentaire:
Enregistrer un commentaire