Part of the Whole


#1



https://www.codecademy.com/en/courses/python-beginner-en-qzsCL/1/4


results:[]
^
SyntaxError: invalid syntax


Why the display keeps on saying this


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


#2

This looks like a dictionary key and value pair. It should be an assignment.

results = []

#3

thank you, this problem is solved but when continuing excuting there is another error:

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

What is the problem with the other part of the code


#4

That is Alice's average, so that means your return is indented (returning on first iteration).


#5

Thanks for this check.
Another problem showed up with:
Make sure you have defined get_class_average

Is it saying I have not defined the function well?


#6

It shouldn't matter, but the space character may not be expected in the code pattern. ( ...age (stu... )

You didn't remove all the indentation on the return statement mentioned above, did you? If you did there should be a console error, return outside of a function or some such.

Paste in your function again, please. Do you have a students list up with the rest of your data?


#7

Here it is after adding the students list:

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

Still incorrect though


#8

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

#9

There are clear signs of indentation issues but we can not tell what those are since your code is not displaying in a discernable way. Is there a topic related to formatting that you might find?


#10

yeah I notice that, copy paste do not seem to get the indentation correct.
But are there any content mistakes?


#12

The first two line of the function are overindented.


#13

the define function part?


#14

Yes. If you look at your formatted post above you can see it. Just back off each line by four spaces.


#15

Thank you very much, problem solved


#16

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