8/9- Part of the whole


#1

Hello. I have been trying this for hours but still no answer. Please help! My code is:

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)

I get the error message: Oops, try again. Make sure you have defined get_class_average
Please tell me where i am going wrong. Thank you so much in advance :smiley:


#2

@13mcenteec it should work just make sure all the other functions being called in this function are correct. and run it again. if it persists, refresh the page, copy and reset the code and then paste it and try it again


#3

Thank you. It worked when i reset the code. I haven't thought of that yet. Thank you :smiley:


#4

I have the same problem and even if I reset the code it does not disappear.

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):
total = sum(numbers)
total = float(total)/ len(numbers)
return total

student = [lloyd, alice, tyler]

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return .1 * homework + .3 * quizzes + .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"

print get_letter_grade(get_average(lloyd))

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)

What is wrong?


#5

total = sum(numbers)
total = float(total / len(numbers))


#6

Thanks for your hint! Unfortunately, it still throws the same error.


#7

did you call the the get_class_average function?


#8

No, I did't!
So I tried now:

get_class_average(students)

after the definition of the function. Is it correct.? It's still the same mistake. :frowning:


#9
  1. that function is returning a value. calling it like this get_class_average(students) will show nothing on the console. you would need to pass this call to print like this print get_class_average(students) to see the result
  2. When you called the method you passed an argument students which is supposed to be a list of your students but in your code there is no variable called students defined anywhere

try to correct these ans lets see if it works


#10

like this:

students = [lloyd, alice, tyler]

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)

print get_class_average(students)

???
Sorry to bother you again


#11

You're missing the get_average function just below the for ... in loop:

  for student in students:
        get_average(student)
        results.append(get_average(student))
    return average(results)

Hope it helps


#12

@mihaistn he has it in his code


#13

Yes it should work now


#14

unfortunately not

still:
Oops, try again. Make sure you have defined get_class_average


#15

can you post the entire code you have now.
This time to format it,
Select the code after you paste it here and press ctrl + k or this </> button in the tools bar


#16
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):
    total = sum(numbers)
    total = float(total)/ len(numbers)
    return total

#student = [lloyd, alice, tyler]
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return .1 * homework + .3 * quizzes + .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"
    
  print get_letter_grade(get_average(lloyd))
    
    students = [lloyd, alice, tyler]
    
    def get_class_average(students):
        results = []
        for student in students:
            results.append(get_average(student))
        return average(results)
    
    print get_class_average(students)

#17

found it! Thanks for all your effort


#18
    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):
    total = float(sum(numbers))/len(numbers)
    return total
def get_average(students):
    homework=average(students["homework"])
    quizzes=average(students["quizzes"])
    tests=average(students["tests"])
    return homework*0.1+quizzes*0.3+tests*0.6
def get_letter_grade(score):
    if score>=90:
        return "A"
    elif score>=80 and score<90:
        return "B"
    elif score>=70 and score<80:
        return "C"
    elif score>=60 and score<70:
        return "D"
    else:
        return "F"
get_average(lloyd)
print get_letter_grade(get_average(lloyd))
students=[lloyd, alice, tyler]
def get_class_average(students):
    result=[]
    for s in students:
        result.append(get_average(s))
    return average(result)
print get_class_average(students)

i dont understand how that code work, cuz if i delete students=[lloyd, alice, tyler]this part, its still working, how function know where from it must take students, since it wasnt declared?