8 part for loop with result


#1



I am unable to understand the logic her someone explain the logic first then explain the bug to correct in the code


Oops, try again. get_class_average([alice]) resulted in an error: global name 'result' is not defined


It should be return the class average it shows B


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


#2

Should not be inside the loop block, but after the loop.


#3

try that also it shows Oops, try again. get_class_average([alice]) resulted in an error: global name 'result' is not defined
"""
students = [lloyd,alice,tyler]
def get_class_average(students):
results = [ ]

for student in students:
    result.append(get_average(student))

return average(results)

"""


#4

thanks for help i found the error it's in results.append i misspelled it


#5

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