Skip to content

Instantly share code, notes, and snippets.

@gabidoye
Created September 5, 2022 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabidoye/5b1b6ce9caa493416e7e7b7e747c1f46 to your computer and use it in GitHub Desktop.
Save gabidoye/5b1b6ce9caa493416e7e7b7e747c1f46 to your computer and use it in GitHub Desktop.
GPA Solution
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