This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Yunn
about 10 years

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

1 vote

Permalink

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

points
Submitted by Joe Durrant
about 10 years

Answer 5317e01152f863d272001c20

0 votes

Permalink

thank you so much!!! i really needed this. I could have struggled through it for half an hour but this really helped!!

points
Submitted by genXtech
about 10 years

2 comments

Yunn about 10 years

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!

Gov Bala about 10 years

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.

Answer 5356ab3380ff33e51700042b

0 votes

Permalink

thanks very much

points
Submitted by duwan16
almost 10 years

Answer 54eb2fe495e378a240005da2

0 votes

Permalink

the use of the word “class” really threw me, thanks for clarifying

points
Submitted by aekhendry
about 9 years

Answer 55fbc54ed3292fe6a80001eb

0 votes

Permalink

Very obligated for you! I’ve created allmost the same script, but with a few mistakes, and your code helped a lot!

points
Submitted by Vadym
over 8 years

Answer 533e3561282ae3d892001115

-1 votes

Permalink

You so rawk dude!! :-D

points
Submitted by Erick
about 10 years