Part of the whole problem


#1



I'm having problem finding what's wrong with my code. It keeps showing this message : Oops, try again. get_class_average([alice]) resulted in an error: list indices must be integers, not str

I don't know what I did wrong. Can anyone here help me out D:


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


#2

@kimkp: You need to pass your iterable, in this case student, not students.

results.append(get_average(students)) # no no
results.append(get_average(student)) # yep
# in this case: student is your iterable while students is your list

Also, make sure to replace your return statement outside your for loop, otherwise on the first loop it will stop the execution of your function and go back to where it was called.

And also:

students = [lloyd, alice, tyler]

Should've been declared outside your function since that's what you'll use to get things working with all your functions.


#3

Okay, so I did what you told me :

students = [lloyd, alice, tyler]
def get_class_average(students):
    results = []
    
    for student in students:
        get_average(students)
        results.append(get_average(student))
   

    return results

but I still got the same error message.


#4

Oh, it's okay now i found the problem... thanks!


#5

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