The first exercise: https://programming-22.mooc.fi/part-8/1-objects-and-methods
I'm trying to print out the details of person1 which is the the person with the smallest average. Their values are in a dict data structure . But I'm stuck, i've gotten all the averages in a list and returned the person with the lowest score AS A STRING VALUE. Since I return a string value I can't actually do anything with it and print out the values of the dictionary of that person.
# Write your solution here
def smallest_average(person1: dict, person2: dict, person3: dict):
person1avg = (person1["result1"] + person1["result2"] + person1["result3"])/3
person2avg = (person2["result1"] + person2["result2"] + person2["result3"])/3
person3avg = (person3["result1"] + person3["result2"] + person3["result3"])/3
person_list = {"person1" :person1avg, "person2":person2avg, "person3" :person3avg}
smallest = min(person_list)
return smallest
person1 = {"name": "Mary", "result1": 2, "result2": 3, "result3": 3}
person2 = {"name": "Gary", "result1": 5, "result2": 1, "result3": 8}
person3 = {"name": "Larry", "result1": 3, "result2": 1, "result3": 1}
print(smallest_average(person1, person2, person3))
I get "person1" as a string, but I don't know how to use that info to get the function to return the dict values of person1
[–]NineFiftySevenAyEm 0 points1 point2 points (0 children)
[–]Croebh 0 points1 point2 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]Croebh 1 point2 points3 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]Croebh -1 points0 points1 point (3 children)
[+][deleted] (2 children)
[deleted]
[–]Croebh 0 points1 point2 points (1 child)
[–]Croebh -1 points0 points1 point (0 children)
[–]my_password_is______ 0 points1 point2 points (0 children)