Data Scientist in Python. Python Lists. 5. Retrieving Values from Lists

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]

ratings_1 = row_1[4]
ratings_2 = row_2[4]
ratings_3 = row_3[4]

total = ratings_1 + ratings_2 + ratings_3 
average = total/3
print(average)

What I expected to happen:
The question states to Assign the fourth element from each row to the new variables. The fourth element of each row is the number of ratings an app has received. Which I thought would be [4] → 3.5, 4.5, 4.5, respectively.

What actually happened:

However, when submitting the answer I get an error. 

"The value of variable ratings_1 is smaller than we expected. It should have value 2974676 but has value 3.5 instead."

When looking at the correct answer I see that the code has [3]. The instructions state the fourth element, wouldn't this be the third element?

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]


ratings_1 = row_1[3]
ratings_2 = row_2[3]
ratings_3 = row_3[3]

total = ratings_1 + ratings_2 + ratings_3
average = total / 3

[4] would be the index 4 which is not the same as the fourth element.

Indices in Python start from 0. So, the first element is at index 0, the second element is at index 1 and so on. The fourth element would be at the index 3.

Exactly what the_doctor said. I was tricked by this practice question just the other day myself. The fourth element is the third index

1 Like

Thank you, everyone!