2

I have a dictionary with the scores for hw, qz, exams and projects. I had to create a function that would calculate the total grade given a dictionary containing the grades. My issue is that we have to drop the lowest quiz grade.I know how to just remove the lowest value in the 'qz' key but if I do that, it is still going to be divided by the total amount of points for quizzes. My question is how would I drop the lowest quiz score so that it changes the total amount of points the quizzes are worth.

Grades = {'hw':[16,27,25], 'qz':[8,10,5], 'ex':[83,93], 'pr':[18,15]}

def Grade_Calculation():    
    One = sum(Grades['hw'])/90 * .25
    Two = sum(Grades['qz'])/30 * .25
    Three = sum(Grades['ex'])/200 * .25
    Four = sum(Grades['pr'])/40 * .25     
    Final_Grade=(One + Two + Three + Four)
    return Final_Grade
joe van horn
  • 61
  • 1
  • 1
  • 4
  • Possible duplicate of [Remove Max and Min values from python list of integers](http://stackoverflow.com/questions/5656670/remove-max-and-min-values-from-python-list-of-integers) – Reti43 Dec 13 '15 at 01:27

2 Answers2

0

You could remove it:

Grades['qz'].remove(min(Grades['qz']))

Or you could simply not use it in the calculation:

sum(sorted(Grades['qz'])[1:])
g.d.d.c
  • 46,865
  • 9
  • 101
  • 111
  • the remove function can't be used for dictionaries I thought. Could you explain your 2nd solution you give? I don't understand how that would work. Thanks – joe van horn Dec 13 '15 at 01:32
  • Quick note, presumably you'd expect a higher total grade when you drop the lowest quiz but, because you're adding (rather than doing some sort of average) grades at the end, you actually get a lower total grade. – Ben Dec 13 '15 at 01:32
  • @joevanhorn _the remove function can't be used for dictionaries_ You're actually removing the value from a list, not from a dictionary. Even though the list exists within a dictionary, it's still a list with all the properties of a list. – Ben Dec 13 '15 at 01:34
  • You might want to check out this reference [link] (http://stackoverflow.com/questions/5656670/remove-max-and-min-values-from-python-list-of-integers) – Ben Dec 13 '15 at 01:35
  • @Ben wow i see what your saying about how the grade would actually end up lower when the lowest quiz grade is dropped. How would you suggest i fix this? Because the quiz grade is divided by 30 since its 10pts for each, if i dropped one it would make it out of 20pts but how do I go about that? – joe van horn Dec 13 '15 at 01:39
  • You could also just drop the points possible down for each category based on the length. Ex. `hwPoss = (len(Grades['hw'])-1)*30 #30pts each hw` for each category. Then do g.d.d.c's `Grades['qz'].remove(min(Grades['qz']))` for loop to remove the least number from the dictionary's list. Then do In your "One, two, three, four" include floating points to divide accurately. – cwahls Dec 13 '15 at 01:49
  • @joevanhorn Hey, Joe, why not just divide it by 20 instead of 30? Or, even more generically, after you drop the value from the list, just divide it by `len(Grades['qz'])*10` – Ben Dec 13 '15 at 02:14
0

As you use hard-coded values anyway and always need to drop one of the scores, why don't you just divide by 20 instead of 30?

Grades = {'hw':[16,27,25], 'qz':[8,10,5], 'ex':[83,93], 'pr':[18,15]}

def Grade_Calculation():    
    One = sum(Grades['hw'])/ (3 * 30)
    Two = sum(sorted(Grades['qz'])[1:])/ ((3 - 1) * 10)
    Three = sum(Grades['ex'])/ (2 * 100)
    Four = sum(Grades['pr'])/ (2 * 20)
    Final_Grade=(One + Two + Three + Four) * .25
    return Final_Grade

If the number of points one can get in a quiz varies it gets more complicated, then you need to have some list that contains the score achievable in each quiz.

NEOatNHNG
  • 904
  • 6
  • 9