Student becomes teacher: Part Of The Whole- error alice should return a number


#1




ERROR: Oops, try again. get_class_average([Alice]) should return a number.

  • if I remove students from results.append() I get append() takes exactly one argument none given.
  • if I store it in a variable a = get_class_average(students) it returns maximum recursion depth
  • if I call get_class_average(students) in my for loop above results.append() returns maximum recursion depth


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!
students = [lloyd, alice, tyler]

for student in students:
    print student["name"]
    print student["homework"]
    print student["quizzes"]
    print student["tests"]
    print

def average(numbers):
    total = sum(numbers)
    total = float(total) / float(len(numbers))
    return total

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["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"
print get_letter_grade(get_average(lloyd))

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


#2

lets look at the instructions:

For each student item in the class list, calculate get_average(student) and then call results.append()

so what should you append to results?

Also, append will update the list for you, no need to also store it in a variable.

but if you look at the instructions:

calculate get_average(student)

get_average is not the same as get_class_average


#3

@stetim94
the results of get_average(student)

def get_class_average(students):
    results = []
    for student in get_average(student):
        results.append(get_average(student)) # doesn't this line do that
    return results

#4

this line wasn't here at first? At least, not in the code you posted on the forum.

Why did you change the loop to this:

for student in get_average(student):

#5

I changed it because I have exhausted my my options to try in attempt to figure the issue and no longer properly understand the instructions. try, try, try again, than ask for help. It seems I don't properly understand the language used or i'm missing something that is way too obvious and simple...
after re-reading again after a fresh nap I see this which is the possible cause for the confusion.

  • For each student item in theclass list, calculate get_average(student) and then call results.append() with that result.

does this say that I need to make a new list with the class members. seems the prior list students in my posted code above is not sufficient.

  • I changed the code to this

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

P.S. thank you for the time and help, it is much appreciated


#6

this is nearly good:

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

now all you need to do, is append get_average(student), only change the append line


#7

when I change the code to:

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

I still get this error:

"Oops, try again. get_class_average([alice]) should return a number"
which is the original error at time of posting.

  • If I add the 's' on students in results.append(get_average(student))
    -I get this error:

It seems they are related but, stated in two different ways.

I also tried moving my students = [lloyd, alice, tyler] but still return with an error.


#8

I swear I tried at least 50 times, but the resulting solution was changing my:

return results

Thanks for all the help @stetim94 :smile:
try try try try try try try try try, then quit try try try then knap, then ask for help, try try try, knap again, then try one last time lol


#10

There is no Lloyd object. lloyd is the name of that dictionary.


#11

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