Thanks @doyinsolamiolaoye, you are doing a great job too!

https://app.dataquest.io/m/312/lists-and-for-loops/4/retrieving-multiple-list-elements

Good day all. This link is the Mission that am currently facing a challenge with. I’ve been able to answer question (1) but (2) has been challenging.

.

2. Compute the average user rating for Facebook, Instagram, and Pandora — Music & Radio using the data you stored in `fb_rating_data`

, `insta_rating_data`

, and `pandora_rating_data`

.

- You’ll need to add the ratings together first, and then divide the total by the number of ratings.
- Assign the result to a variable named
`avg_rating`

. - As a side note, we could calculate the average rating here a little bit better using the weighted mean — we’ll learn about the weighted mean in the statistics courses.

I used the following code to attempt the answer but it was not correct:

avg_rating = [row_1[0] + row_2[0] + row_5[0]] / 3

When I run the code, i get an error output message thus:

TypeErrorTraceback (most recent call last)

in ()

7 insta_rating_data = [row_2[0], row_2[3], row_2[-1]]

8 Pandora_rating_data = [row_5[0], row_5[3], row_5[-1]]

----> 9 avg_rating = [row_1[0] + row_2[0] + row_5[0]] / 3

TypeError: unsupported operand type(s) for /: ‘list’ and ‘int’

Hello @olujimiabatan,

The first error is that you calculated the value of `avg_rating`

the wrong way. The instruction states that: *Compute the average user rating for Facebook, Instagram, and Pandora — Music & Radio using the data you stored in fb_rating_data, insta_rating_data, and pandora_rating_data*.

For each of the data stored in the lists, the value of the user rating is stored in the last element of each list, as such the value of the `average user rating`

will be solved by adding up the last element of the three lists and dividing the result by 3.

Secondly, the result of adding the user rating should be put inside a parenthesis `()`

and not square brackets `[]`

.

After effecting these changes, your code should look like this:

```
fb_rating_data = [row_1[0], row_1[3], row_1[-1]]
insta_rating_data = [row_2[0], row_2[3], row_2[-1]]
pandora_rating_data = [row_5[0], row_5[3], row_5[-1]]
avg_rating = (fb_rating_data[-1] + insta_rating_data[-1]+pandora_rating_data[-1])/3
```

I hope this helps.

Wow, it really did work. Thanks a lot Omo-Iya. I now understand where I went wrong but what I do not understand is why we had to repeat the [-1] index number alone at the end of each ratings when trying to find avg_rating?

To extract the last element of each list, you have to use the format `name_of_list[-1]`

. So we have to repeat the indexing for each list.

`fb_rating_data[-1]`

returns the value of the last element in the `fb_rating_data`

list which is the user rating of that list. We do the same for the other two lists(`insta_rating_data`

and `pandora_rating_data`

).

Hence we have;

`fb_rating_data[-1] + insta_rating_data[-1]+pandora_rating_data[-1]`

.

Now I understand better. I think that I’m going to start calling you Dr. Dymistifier! Thanks again Omo-Iya.

I am glad you understand better. If you have a question next time, Kindly create a different Q&A post so the question and its solutions are easily differentiated from other questions.

Happy learning!