I’m not sure why this code is throwing an error. I’m told that I’m dividing by zero. So the length of the non_free_social_games_ratings
list that I’ve created is zero? I’m not sure how or why that is.
opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
opened_file.close()
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:
free_games_social_ratings.append(rating)
avg_free = sum(free_games_social_ratings) / len(free_games_social_ratings)
# Non-free apps (average)
non_free_social_games_ratings = []
for item in apps_data[1:]:
rating = float(item[7])
genre = item[11]
price = float(row[4])
if (genre == 'Social Networking' or genre == 'Games') and price != 0:
print("Here")
non_free_social_games_ratings.append(rating)
avg_non_free = sum(non_free_social_games_ratings) / len(non_free_social_games_ratings)
My code is almost identical to the one that the answer shows. I could copy and paste and move on, but I’d really like to know why my code isn’t working.
This error is happening on 7. Combining Logical Operators mission of Conditional Statements in the Python Fundamentals course.