Final answer error

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

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_2[3], row_2[-1]

avg_rating = (fb_rating_data[3] + insta_rating_data[3] +
pandora_rating_data[2]) / 3

The answer
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[4]]
pandora_rating_data = [row_5[0], row_5[3], row_5[4]]

avg_rating = (fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2]) / 3

Im confused, I thought this would be the correct answer but when I viewed the answer they were calling the second element when the question says to add the ratings together, calling the second element doesent make sense to me, could anyone enlighten me on this

hey @Hashim_younis

for a List type variable the index starts at 0. so if a list has 5 elements in total, the index values would be like so:

image

so in the list pandora_rating_data = [row_5[0], row_5[3], row_5[4]] there would be total 3 elements starting at index 0, then next element will be at index 1 and next element will be at index 2.
hence 2nd element means the one at index position2. in this case:

pandora_rating_data[2]

hope that helps.

1 Like

I understand that my answer of 4.16 is no correct, what should it be

1 Like

hey @becon12

it should be 4. ratings of fb + insta + pandora >> (3.5 + 4.5 + 4.0) /3 = 4.0