The words in For xxx in dataset

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

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]

app_data_set = [row_1, row_2, row_3, row_4, row_5]

rating_sum = 0

For row in app_data_set:
rating = row[-1]
rating_sum = rating_sum + rating
print(rating_sum)

avg_rating = rating_sum / len(app_data_set)

  1. when the dataset is number only, we use “For value in (dataset name)”. when the dataset has mixed number and string, we use “For row in (dataset name)”, is it right?

  2. Why it needs to add “print(rating_sum” in the loop?

value and row are just variable names. You could also use v or asd instead or any other valid variable name, but it’s best to use good, easily understandable variable names.

So that you can print out the rating_sum value at each iteration since at each iteration of the for loop that value changes.

As per the instructions, printing it is not required.

2 Likes