Created
September 5, 2022 16:31
-
-
Save gabidoye/5b1b6ce9caa493416e7e7b7e747c1f46 to your computer and use it in GitHub Desktop.
GPA Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
students = { | |
"name":"y", | |
"studentid":"z", | |
"courses":[ | |
{ | |
"Coursetitle":"English", | |
"Unit":2, | |
"CourseCode":"ENG", | |
"score":60 | |
}, | |
{ | |
"Coursetitle":"Maths", | |
"Unit":3, | |
"CourseCode":"MAT", | |
"score":80 | |
} | |
] | |
} | |
print() | |
# def gpa(val): | |
# cgpa= (val['courses'][0]['score'] * 4) | |
# print(cgpa) | |
def gpa(dicts): | |
gp=[] | |
sum_of_gp=0 | |
for key, value in dicts.items(): | |
if key=='courses': | |
count =len(value) | |
# print(count) | |
# print(value) | |
for val in value: | |
for key in val: | |
if key=='score': | |
# gp.append(val[key]) | |
sum_of_gp += val[key] | |
# print(gp) | |
return sum_of_gp /count | |
print(gpa(students)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment