Retrieving Multiple List Elements Error

Screen Link:

My Code: row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
row_2 = [‘Instagram’, 0.0, ‘USD’, 2161558, 4.5]
row_3 = [‘Clash of Clans’, 0.0, ‘USD’, 2130805, 4.5]
row_4 = [‘Temple Run’, 0.0, ‘USD’, 1724546, 4.5]
row_5 = [‘Pandora - Music & Radio’, 0.0, ‘USD’, 1126879, 4.0]
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

So I figured it out by looking in the discussions community. However, I wanted to make sure I understand the reason why. My question is about computing the avg user ratings of Facebook, Instagram, and Pandora. I added them together then divided it by the total number of ratings. 

What actually happened: This was how I had it :  avg_rating = [row_1[-1] + row_2[-1] + row_5[-1]] / 3. It kept giving me error sign. I even made sure I had the right index number. When I came to the discussions community I saw it was set up like the code I have above.  So is this reason why I had errors was because I use the bracket [  instead of the parentheses (  ? Would love some feedback ! please and thank you!

Replace this line with the output/error

<!--Enter other details below: -->
1 Like

Hi, @amouzout,

You are right, the problem lies in the use of brackets instead of parenthesis in your code as below:

avg_rating = [row_1[-1] + row_2[-1] + row_5[-1]] / 3 

In Python using brackets [] means you are making a list.

The error message you get from your code above should be:
TypeError: unsupported operand type(s) for /: 'list' and 'int'

This tells you that the division between a list and an int is not supported in Python. It also proves that the result of [row_1[-1] + row_2[-1] + row_5[-1]] is a list.

I would suggest you google the error message first in the future and try to understand what the error message means, and deduce where the problem lies and how to solve it. Trust me, there are no better feelings in the world than solving your own bugs. :laughing:

A side note, a well-formatted question help us fellow learners help you better, here’s a guide --> Introducing guidelines for all technical questions in our Community.

1 Like

Hi @veratsien !

Thank you so much. That was exactly what the error message said! I was going crazy because I had computed averages in previous exercises and it didn’t give me an issue so I was just so confused about what it could be.

Thank you for clarifying I will take note of this and will make sure to google error messages next time, you’re right it would be helpful to understand what it means lol.

Yes, I will use the guide for next time - this was my first time asking a technical question so it was a bit all over the place. Thank you for your help :smile:


You are very welcome, I’m glad to be of help. And welcome to the community! :grinning: