Answer not acceptable as correct

Screen Link: https://app.dataquest.io/m/312/lists-and-for-loops/2/indexing

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[3.5]
ratings_2 = row_2[4.5]
ratings_3 = row_3[4.5]

total = ratings_1 + ratings_2 + ratings_3

average = total/3

What I expected to happen:
For the machine to print correct answer.

What actually happened:
TypeErrorTraceback (most recent call last)
in ()
3 row_3 = [‘Clash of Clans’, 0.0, ‘USD’, 2130805, 4.5]
4
----> 5 ratings_1 = row_1[3.5]
6 ratings_2 = row_2[4.5]
7 ratings_3 = row_3[4.5]

TypeError: list indices must be integers, not float```

Paste output/error here
TypeErrorTraceback (most recent call last)
in ()
3 row_3 = [‘Clash of Clans’, 0.0, ‘USD’, 2130805, 4.5]
4
----> 5 ratings_1 = row_1[3.5]
6 ratings_2 = row_2[4.5]
7 ratings_3 = row_3[4.5]

TypeError: list indices must be integers, not float

hi @phyladiamah

you are giving the element itself rather than index-position of that element in the list.

to extract rating the code should be row_1[4] where 4 is the index of rating value.

image

1 Like

I can accept this. However, it was not pointed out in the instructions anywhere that the fourth elements in the lists had to be converted to integers. This should’ve been made clearer.

hi @michael08huff

Welcome to the DataQuest Community!

I am not sure about the conversion part as I don’t see any task related to conversion in the instructions. Could you please elaborate on this further?
Thanks.

I tried with an index number fourth, but there was an error message for conversion. So, I fixed it and still received an error for the answer. I think the main problem is an index number. The instruction indicates to find the fourth index number:row_1[4], but the answer was calculated with the third index number. When I submitted the code using row_1[3], it was fine. Could you please double check the index number in the instruction with the answer? Please let me know If my reasoning is not correct. Thank you!!

  1. Assign the fourth element from the list row_1 to a variable named ratings_1 . Don’t forget that the indexing starts at 0 .
  2. Assign the fourth element from the list row_2 to a variable named ratings_2 .
  3. Assign the fourth element from the list row_3 to a variable named ratings_3 .
  4. Add the three numbers retrieved together and save the sum to a variable named total .

Welcome to DQ Community @mohngelay.nl

that’s the trick with array and lists. the mission content and instructions both give you info on that.
unlike roll call or sequence numbers which start with 1, index positions for lists and arrays in python (or other programming languages) start at 0. So when you read 4th element - start counting it as - 0, 1, 2, 3.
observe here that although we reach index 3 we have counted 4 items/elements.

basically if the list has n elements, then the last index position is always n-1. so for a list of 4 items we have 4-1 = 3 as the index position for the 4th element.

This is screenshot from the mission itself. (the solution post also has a similar one):
image

The instructions wants us to calculate average of total number of ratings as received by the app. And not the total rating the app has. So it’s this big number - 2974676 etc. and not 3.5.

hope that helps.

1 Like

Thank you so much Rucha, finally everything makes sense!