This forum is now read-only. Please use our new forums! Go to forums
8/9 Solution w/Explanation Part 2
Ok, we’re on! Let’s proceed to the second step of the instruction. For those who just joined, the first part is here: http://www.codecademy.com/forum_questions/531778f1548c35a18c004647
2. First, make an empty list called results
.
I really hope that you have it figured out, but just in case:
results = []
Again, this is what you should have at the end of this step:
students = [lloyd, alice, tyler]
def get_class_average(students):
results = []
3. For each student
item in the class
list, calculate get_average(student)
and then call results.append()
with that result.
This is a tricky one. It mentions a class
list, but there’s no such list in our code. What is really meant in this instruction point is the students
list. Apart from that little comment, there isn’t much to do here. Just follow the instruction.
Here’s what you should get:
students = [lloyd, alice, tyler]
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
We go thought the students
list, calculate an average for each student using the previously defined get_average(student)
function, and append this average to the results
list using .append()
4. Finally, return the result of calling average() with results.
Once again, just do what it tells you to do here. For now, your results
list isn’t empty anymore, it contains the average grades for each of the students. So now you get the average grade for all of your students using the previously defined average()
function.
By following this step-by-step “guide”, you’re definitely going to pass this exercise. To sum up, here’s how your code should look when you’re done (just the part that you write in this exercise):
students = [lloyd, alice, tyler]
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
Good luck and feel free to ask questions! Hope this helps!
Answer 531cdd6452f863ffc1006290
Thanks so much!
I’ve noticed that the wording on some of the tasks can make it confusing, thanks for explaining it line by line
Answer 5317e01152f863d272001c20
Answer 5356ab3380ff33e51700042b
Answer 54eb2fe495e378a240005da2
Answer 55fbc54ed3292fe6a80001eb
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
I’m really glad I could help someone out as I struggled through it for a while myself. Good luck and thnx for your feedback!
thanks yunnica.. was stuck for a while here.. oddly, i was getting the average to be 80.366667, but the average was 85.. i just had to shift the return to the left so that it wasn’t inside for__in___ statement.