Part of the whole. what is wrong with my code


#1



i am really stuck i don't know what to do


i get this error when i submit the code
Oops, try again. get_class_average([alice]) resulted in an error: 'float' object has no attribute 'append'


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


#2

well first off I believe your results should equal [] not {}


#3

First, I think that you need to append get_average(student) to results, rather than setting results equal to it because you are changing what the results variable is.
Also, @bibleman13 is right, results should be equal to an empty array, [], not dictionary.
Your return command is inside of your for loop, which will result in your function ending on the first iteration of your for each loop, so you need to unindent the line with the return command once.


#5

thanks but im still getting the error message


#6

post your updated code ! :smiley:


#7

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

i get a new error aswell

File "python", line 46
return average(results)
^
IndentationError: unindent does not match any outer indentation level


#8

sorry i didnt indent it on my post like the code

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

#9

so basically your return statement, now that I can see the indention, needs to be in line with your for statement so tab it over once I believe


#10

thank you so much i have been stuck on that forever! :smile:


#11

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