Question: I need to debug my code and I am not sure why my output is missing a value. When I check it I get the
I need to debug my code and I am not sure why my output is missing a value. When I check it I get the following
The call letter_grades({'abc123': 0, 'abc456': 65, 'jms457': 50, 'jms123': 60, 'xyz123': 70, 'xyz456': 80, 'wmw4': 90}) returns {'abc123': 'F', 'abc456': 'D', 'jms457': 'F', 'jms123': 'D', 'xyz123': 'C', 'wmw4': 'A'}, not {'abc123': 'F', 'abc456': 'D', 'jms457': 'F', 'jms123': 'D', 'xyz123': 'C', 'xyz456': 'B', 'wmw4': 'A'}.
Also getting this error
The call letter_grades({'abc123': 0, 'abc456': 65, 'jms457': 50}) returns {}, not {'abc123': 'F', 'abc456': 'D', 'jms457': 'F'}. My output is missing the bolded value and I'm not sure why this is happening?
def letter_grades(adict): """ Returns a new dictionary with the letter grades for each student. The dictionary adict has netids for keys and numbers 0-100 for values. These represent the grades that the students got on the exam. This function returns a new dictionary with netids for keys and letter grades (strings) for values. Our cut-off is 90 for an A, 80 for a B, 70 for a C, 60 for a D. Anything below 60 is an F. Examples: letter_grades({'wmw2' : 55, 'abc3' : 90, 'jms45': 86}) returns {'wmw2' : 'F, 'abc3' : 'A', 'jms45': 'B'}. letter_grades({}) returns {} Parameter adict: the dictionary of grades Precondition: adict is dictionary mapping strings to ints """ res={} for key in adict: if adict[key]>=90: res[key]="A" elif adict[key]>=80 and adict[key]<90: adict[key] elif>=70 and adict[key]<80: res[key]="C" elif adict[key]>=60 and adict[key]<70: res[key]="D" elif adict[key] < 60: res[key] = "F" else: return {} return res
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
