Part of the Whole


#1



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


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


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]
}
students = [lloyd, alice, tyler]
# Add your function below!
def average(numbers):
    total = sum(numbers)
    total = float(total)
    return 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
    return homework + quizzes + tests
    return grade
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(lloyd)
def get_class_average(students):
    results = []
    for item in students:
        get_average(students)
        results.append()
        results = average(results)
    return results


#2

lets start here:

get_average(students)

get_average is designed to calculate the average grade for a single student, students is a list with multiply students

once you fixed that, you don't store this average result anywhere, so how are you going to append it to your results list?

results.append()

you are not appending anything?

and finally:

results = average(results)

why would you do this inside the loop? Inside the loop you are appending to the list, once the list has all its data, you should calculate the average


#3

so do I have to get_average on Lloyd, alice and tyler individually?


#4

no, you have a loop which loops over the list, you can use the iterator to get the average for each student in students


#5

I don't understand can you please explain it in the most simple terms.


#6

can i see an updated version of your code?

here:

get_average(students)

you need to change students to your for loop iterator, which contains the individual students

once you done that, you need to store this result in a variable so you can append it to your results list


#7

I am sorry I still don't understand what I need to do


#8

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]
}
students = [lloyd, alice, tyler]
# Add your function below!
def average(numbers):
    total = sum(numbers)
    total = float(total)
    return 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
    return homework + quizzes + tests
    return grade
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(lloyd)
students = [lloyd, alice, tyler]
def get_class_average(students):
    results = []
    for item in students:
        results = results.append(get_average(student))
    return results

#9


#10

I have posted my code but it will not allow me to post it again.


#11

.append() updates the list for you. No need to store it in a variable as well.

you have want to append the get_average of student, change your loop iterator to student

you should return average(results)


#12

et_letter_grade(lloyd)
students = [lloyd, alice, tyler]
def get_class_average(students):
results = []
for item in student:
results.append()
return average(results)


#13

what is so unclear about my instructions?


#14

my code is now:
def get_class_average(students):
results = []
for student in students:
result = get_class_average(student)
result.append(results)
return average(results)


#15

that is not an answer to my question? and frankly, you are just trying now. That doesn't work


#16

why doesn't it work? Please be patient with me I am new to programming.


#17

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