The following are links to additional questions that our community has asked about this exercise:
This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!
Not seeing your question? It may still have been asked before – try () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().
I have completed this exercise but I want to know how the computer recognises that the ‘average()’ is the average of the contents in the brackets, since it still shows up as red letters?
The values in square brackets are lists. We pass a list to the average function, where it is tallied up to arrive at a total, then divided by the number of items in the list (len(numbers)) to return an average.
The values in the students list are names of references that point to individual student dictionaries. When we pass one of them into the get_average() function, the function is able to see inside that dictionary and extract the data.
Those lines contain only the data objects. The functions are the means of extracting and computing the data, both individually, and as a whole (class_average).
Okay, but at which point in the functions does it use the data objects? I’m just trying to pinpoint the code that does this as I am struggling to understand how Python knows to use the student data without actually mentioning the variable names.
Is it between line 27 and 29 where the argument of the function followed by the key in square brackets is?
Why would it need to care about or know that?
Maybe it should operate on whatever data is provided to it when it is called.
If you have a function named add, then it should probably add the two numbers provided to it instead of always returning 12 because it’s decided 5 and 7 are the numbers that need adding. Being able to tell add which values to operate on is what makes add useful.
We provide a list of references (the variables to which you refer?) and it is our program, not Python, that extracts the data according to our needs. WE are the ones who know about the data, and how it is organized, so WE must write the code to give us the outcome we desire.
def get_class_average(class_list):
called on the students list,
print (get_class_average(students))
Given that we are passing in a list, then we must iterate over that list to gain access to the individual student’s data., by name.
for student in class_list:
Note that the name class_list is arbitrary, but it does tell the reader what the inbound object should represent.
i get this error with y code get_average(alice) raised the following error: global name ‘homework’ is not defined can someone explain to me why ? are the values or ’ and " different?
Not sure if there might be something else amiss. When you paste code in a post, make sure you use the </> button in the menu bar. I find it easiest to click the </> first, and then paste code in the space indicated. It will preserve indentation, formatting and special characters, so the rest of us can see your code the way you originally typed it.
g in the above is an object, one of the dictionaries, alice, tyler or lloyd. The function would be called with one of those references as the argument.