Im stuck :(


lloyd = {
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
alice = {
    "name": "Alice",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]

# Add your function below!
def average(numbers):
    return float(sum(numbers))/len(numbers)
def get_average(student):
    homework= average(student["homework"])
    quizzes= average(student["quizzes"])
    tests= average (student["tests"])
    return 0.1*homework + 0.3*quizzes + 0.6*tests    

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"
    else :
        return "F"
def get_class_average(students):

Define a function called get_class_average that has one argument students. You can expect students to be a list containing your three students.
First, make an empty list called results.
For each student item in the class list, calculate get_average(student) and then call results.append() with that result.
Finally, return the result of calling average() with results.

i´ve tried many ways but i can´t get it


Seems like you need a "for" loop to iterate through that list
This should work:

for item in students:
""" calculate get_average(student) and then call results.append() with that result.
Finally, return the result of calling average() with results."""

Also try to change this:

to this:

results = []

Hope it helps! :grin:


def get_class_average(students):

for item in students:

one of the many options i typed, nothing works


This should work:

for student in students:
    return results

Try to review the main concepts of for loops in python


nothing yet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


my bad, this should work:

def get_class_average(students):    
  for student in students:
  return average(results)

'results' needs to be out of the 'for' loop so it doesn't reinicialize avery time the loop runs, also 'return' need to be out to return the list of results when the loop ends.


And just a small critique, Step 4 says, "Finally, return the result of calling average() with results." You need the average of the results returned not just the results :thumbsup:

return average(results)


I just missed that, thank you for the clarification.
I edited my answer so it returns the average now ^^


No problem! Sorry I would just like it but I am out of likes for the next 22 hours haha


i hava a question then, the for loop has as his general form:

for variable in list name

In this excersise we´re typing :

for student in students, student is an argument for the get_average() function and students is an argument for the get_class_average() function-------> so i don´t get the relation we´re typing between student and students in the for loop


It's just a name we give in this case, because "students"(plural) it's a list of students so it's natural to refer to a member of that list as a "student"(singular).


would you help me with the next excersise?

Finally, print out the result of calling get_class_average with your students list. Your students should be [lloyd, alice, tyler].
Then, print the result of get_letter_grade for the class's average.


sure but make a new topic about it or share me the link if you already did.



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.