IDNLearn.com offers a comprehensive solution for finding accurate answers quickly. Join our knowledgeable community and access a wealth of reliable answers to your most pressing questions.
Answer:
The function is as follows:
def get_gpa(mydict):
gpa = 0
kount = 0
for course_code, gp in mydict.items():
if course_code == 'cs120' or course_code == 'cs210' or course_code == 'cs245':
gpa += float(gp)
kount+=1
return (gpa/kount)
Explanation:
This defines the function
def get_gpa(mydict):
This initializes gpa to 0
gpa = 0
This initializes kount to 0
kount = 0
This iterates through the courses
for course_code, gp in mydict.items():
If course code is cs120 or cs210 or cs245
if course_code == 'cs120' or course_code == 'cs210' or course_code == 'cs245':
The gpa is added
gpa += float(gp)
And the number of courses is increased by 1
kount+=1
This returns the gpa
return (gpa/kount)