Part of the whole


#1



This is my code

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


File "python", line 56
SyntaxError: 'return' outside function


Replace this line with your code.


#2

this is currently your function:

def get_class_average(students):
    results = []

are you sure that is right?


#3

//My new piece of code

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

// error it is showing

Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected

PS - I am frustrated, please help me


#4

Yup i think i am sure ...it is right


#5

a function ends the moment a return keyword is reached

if a return keyword is reached in a loop, the loop will break

so your loop breaks in its first iteration


#9

This will help. Try keeping the return of 'average' out of 'for' loop. Mind the indent.


#10

Tysm Megasolver .. :smiley:


#11