8/9 Part of the Whole


#1

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

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

What am I doing wrong?


#2

This is what I did:
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)

students = [lloyd,alice,tyler]
print get_class_average(students)

your return student should indent in the same line as for


#3

oops i mean statement*


#4

It keeps saying "File "python", line 50. SyntaxError: 'return' outside function" Which means that it is talking about "return average(results)." I don't know how to make it an outside function.


#5

For the furure when posting code highlight your code and use the </> key or do the following

```python
# sample code
```

Those special characters are from the tilde key which is the top-left most key under your f-keys.

Now on to your issue. @gurung85 is correct your code should look as follows.

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

Indention is the equivalent of c, c++ brackets

Example:

int main ()
{
    cout << "This is inside of the code, printing stuff";
}

If the indention does not match the scope then python does not know what to do, you should always remember that computers are the dumbest person in the world only capable of doing what we tell them.