Blue Week Special Offer | Brighten your week!
days
hours
minutes
seconds

The Output for " print(nonfree_games_social-ratings) after the conditional statements if " comes out as list of lists rating values. Isn't supposed to be a list of rating values?

Screen Link:
https://app.dataquest.io/m/313/conditional-statements/7/combining-logical-operators

My Code:

Replace this line with your code

What I expected to happen:

What actually happened:

Replace this line with the output/error

Hi @azrul_arif95,
Yes, it is supposed to be a list of rating values. Could you post your actual code?
Thanks!

Hello @azrul_arif95 Welcome to the DataQuest Community. non_free_games_social_ratings should be a 1D list that holds ratings if (genre == 'Social Networking' or genre == 'Games') and price != 0.0

For assistance, I think it would be nice for you to provide us with your code so that we can provide guidance where necessary.

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

non_free_games_social_ratings = []
for row in apps_data[1:]:
    rating = float(row[7])
    genre = row[11]
    price = float(row[4])
    
    if (genre == 'Social Networking' or genre == 'Games') and price != 0.0:
        non_free_games_social_ratings.append(rating)
        
avg_non_free = sum(non_free_games_social_ratings) / len(non_free_games_social_ratings)

# Non-free apps (average)

print(avg_non_free)

Above is how I went through with it.

opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

non_free_games_social_ratings =
for row in apps_data[1:]:
rating = float(row[7])
genre = row[11]
price = float(row[4])

if (genre == 'Social Networking' or genre == 'Games') and price != 0:
    non_free_games_social_ratings.append(rating)

print(non_free_games_social_ratings)

Ive shared my code above hope you can help me thank you!

Hi ive shared my code as above, out of curiosity I wanted to print out the outcome for " non_free_games_social_ratings " after appended the rating value into it. But the outcome return as list of lists.

Hi @azrul_arif95,
Your code seems correct and should return a list of the rating values. I cannot see from the code posted but it is likely you have indented the print statement. Is print(non_free_games_social_ratings) inside the if statement?

print(non_free_games_social_ratings) should neither be inside the for loop nor the if statement and the output will be a list. The code should be as below:
image

I mistakenly put the print function inside the loop so it is indented! Followed the code you share and now the outcome return as only a list. Thanks!! @enext7771 @info.victoromondi

Great! @azrul_arif95 if my response has helped please mark as solution. Thanks!