AnsweredAssumed Answered

how to do I call a list from a dictionary to a function?

Question asked by tpamps96 on Jul 25, 2019
Latest reply on Jul 25, 2019 by bixb0012

I have been taking an online python course and figured I'd try to create a grade calculator to apply what I have learned so far. I got my calculator to work, but I am stuck on one part. 


I want to call the "exams" list seen in bold to the def get_average function. I want to replace the bolded part of the function to something that calls the "exams" list and does the same thing as the current bolded portion of the function.


I guess the question is how to do I call a list from a dictionary to a function?


tay = {
"name": "Taylor",
"attendance": [100.0, 0.0, 100.0, 100.0, 0.0, 100.0, 100.0, 100.0, 100.0, 100.0],
"labs": [75.0, 80.0, 95.0, 95.0, 100.0],
"exams": [84.0, 88.0, 91.0, 95.0], 
#if you know anyway to make this a shorter script please let me know... call in list "exams"?
#I would also like to dump grades and weights of grades into a text file and call them into the script... not top priority though.


def average(numbers):
total = sum(numbers)
total = float(total)
return total/len(numbers)


def get_average(student):
attendance = average(student["attendance"])
labs = average(student["labs"])
return 0.05 * attendance + 0.15 * labs + 0.20 * tay["exams"][0] + 0.20 * tay["exams"][1] + 0.20 * tay["exams"][2] + 0.20 * tay["exams"][3]


def get_letter_grade(score):
if score >= 90:
return "A "
elif score >=80:
return "B"
elif score >=70:
return "C"
elif score >=60:
return "D"
return "F"


print get_letter_grade(get_average(tay))