8. Part of the Whole Error: Needs Integer and not String


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/4?curriculum_id=4f89dab3d788890003000096

Oops, try again. get_class_average([alice]) resulted in an error: list indices must be integers, not str

Not sure how to make it print an integer and not string.


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)
    return float(total) / len(numbers)
    
def get_average(student):
    homework = average(student["homework"]) * 0.1
    quizzes = average(student["quizzes"]) * 0.3
    tests = average(student["tests"]) * 0.6
    avefinal = ( homework + quizzes + tests)
    return avefinal

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"
a = get_average(tyler)
print get_letter_grade(a)

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


#2

@20dannyb,
What are you doing here

        get_average(student)
        results.append(get_average(student))

AND
then
as you have 1 list =results=
you are using that =list= as an argument
in a call on the get_average() function.....??!!


#3

I too have the same problem - can anyone help?

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)

return float(total) / len(numbers)

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:
return 'B'
elif score >= 70:
return 'C'
elif score >= 60:
return 'D'
else:
return 'F'

get_letter_grade(get_average(lloyd))

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


#4

@leonhard.wettengmx.n

Yes but....How do I make it give me an integer and not a string......?


#5

@20dannyb,
Instead of calling the get_average() function
you should be calling the average() function.....


#6

@leonhard.wettengmx.n

Okay, that solved my problem and passes #8. But it returns the exact same thing. Whether I call the get_average() function or the average() function, I get C printed in the console. How does that make sense? It's the same exact letter in the console but codecademy says one is wrong and one isn't. Explain please


#7

hey, not sure what your problem is but I see one error in your get_class_average definition
this:

should use n variable and not students as you are looping by n


#8

@20dannyb,
Please post the FULL code you are using now...
and mention the EXACT Oops or Error message you are getting....
and mention the course section we are now writing about....