Python Problem: lists

Hello, I have a homework assignment and I just had a couple of questions about it.
Here is the problem directions and the given info for reference,

“There are ten names and five lists of test scores. The correspondence
between the names and the test scores are determined by positions. For example, the test scores for Cindy are 67, 92, 67, 43, 78. Drop the lowest of the five test scores for each student and average the rest and determine the letter grade for that student.”

names = ['April','Bill','Cindy','Dave','Emily',  'Frank','Gene','Hank','Irene','Jeff']
test1 = [35,21,67,45,88,  77,63,96,89,88]
test2 = [11,67,92,35,89,  25,78,94,81,63]
test3 = [94,33,67,34,67,  88,55,99,23,43]
test4 = [27,83,43,67,93,  45,67,77,86,90]
test5 = [43,76,78,45,65,  99,65,65,79,43]

Okay so, I know how to do the problem, but I was wondering if there was a useful method to SIMPLIFY the process. I am writing the code the way he taught us in class, but he also does not mind if we branch out and use other functions. If anyone has any suggestions that would be awesome! If this doesn’t make sense or I need to clarify something just let me know please.

This is my code below… see how I have to repeat the same process for each test score. I will have to do this several times (printing sum, average, and grade) and I would like to learn a more efficient method.
**** Note that each student’s test grades correspond vertically****

print (sum(test1)-min(test1))
print (sum(test2)-min(test2))
print (sum(test3)-min(test3))
print (sum(test4)-min(test4))
print (sum(test5)-min(test5))

print ((sum(test1)-min(test1)) / (len(test1)-1))
print ((sum(test2)-min(test2)) / (len(test2)-1))
print ((sum(test3)-min(test3)) / (len(test3)-1))
print ((sum(test4)-min(test4)) / (len(test4)-1))
print ((sum(test5)-min(test5)) / (len(test5)-1))

which gives the output :
648
624
580
651
615

72.0
69.33333333333333
64.44444444444444
72.33333333333333
68.33333333333333

^^ I will round those later

THANKS!!

Please read the task again, what you are doing is wrong.
Those are 10 students, who each participated in 5 tests and you have to determine their grades based on their best 4 results.
So for a start, you need to get 10 grades.
What you did instead is creating the average grade of each test minus the worst result.

Starting with April, the first student, you need to add up
test1[0]+test3[0]+test4[0]+test5[0] = 35+94+27+43 = 199
199/4 = 49,75 → letter Grade (A,B,C… whatever)
(test2[0] with 11 points is the worst result, hence discarded)

And you have to do that 10 times - for each student. The horrible version is 10 times this:

( test1[0]+test2[0]+test3[0]+test4[0]+test5[0] - min( test1[0],test2[0],test3[0],test4[0],test5[0]) ) / 4

Given only the indices change, you could put it into a for-loop using range(len(students))

Ohh okay I see, I did not even notice! Just copied the example he gave in class, thanks! So will I need to write that process out 10 times, no other way to shorten it? If not that alright :grinning:

I mean, there would be a couple of ways to shorten it.
You could make a for-loop from 0 to 9 instead of copying that line 10 times.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.