After some trial and error I managed to finish the 'student becomes the teacher' lesson. Admittedly, I had to browse the forums for the last part, as some piece of code that was added in the beginning was deleted further down the lesson. See below for my code.
Today I went over the code again and found out that I don't yet fully understand how it all works. Mainly talking about how Python knows certain things and how functions and for loops work. I wrote down how I think it works, and it would be great if someone could give some feedback or point me in the right direction if I'm mistaken somewhere.
Am I correct that the function def average(numbers): doesn't do anything in this lesson?
In the def get_average(student): function 3 variables are made and added together. How does Python know what value's to pick? Is the average(student["homework"]) part referring to the previous created list in the dictionary? If so, how does Python know which list to take? Since there are multiple lists with the same name.
- In the function def get_class_average(students): the for loop iterates over every student, executes the def get_average(student): function for each, and adds the result to the empty list.
Is there here also a reference to the actual created list students (i.e students = [lloyd, alice, tyler])? And is that the parameter of the function, the students in the for loop, or perhaps both/none?
I'm asking mainly because if you replace students in both print statements with [lloyd, alice, tyler], the code still works perfectly fine. Even though there is no reference to the students any more. Like so:
print get_class_average([lloyd, alice, tyler]) print get_letter_grade(get_class_average([lloyd, alice, tyler]))
- When you create the list students = [lloyd, alice, tyler] it seems to me that it auto-refers to the names of the three dictionaries (if you look at the functions). Is this something Python does automatic?
Hope my questions are clear and someone can answer them for me.