BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Conditionals- Problem 1 issue

This issue is related to If -statements problem set. The issue is on Problem 1 in this ‘If-statements’ chapter.

My code looks correct to me but there may be a mistake I am overlooking. Basically here is
Screen Link:
Here is the link to the problem: Learn data science with Python and R projects

**# INITIAL CODE**
opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

free_apps_ratings = []
for row in apps_data[1:]:
    rating = float(row[7])
    # Complete the code from here
    price = float(row[5])
    
    if price == 0.0:
        free_apps_ratings.append(rating)
print(free_apps_ratings[:5])

avg_rating_free = sum(free_apps_ratings)/len(free_apps_ratings)

**What I expected to happen:**

avg_rating_free
float (<class 'float'>)
- actual + expected

- 0
+ 3.3767258382642997
Find attached expected screenshot![Screen Shot 2021-10-14 at 1.25.31 PM|537x500](upload://nEzygFXlzdkruBZDsihoCAHgl9O.png)


What actually happened: 

avg_rating_free
float (<class ‘float’>)

  • actual + expected

  • 0

  • 3.3767258382642997

Hi again @simi-1, I think I may have found your problem… Check out the header for apps_data to see if you can spot it as well:

for idx, header in enumerate(apps_data[0]):
    print(idx, header)

Output: 

0 id
1 track_name
2 size_bytes
3 currency
4 price
5 rating_count_tot
6 rating_count_ver
7 user_rating
8 user_rating_ver
9 ver
10 cont_rating
11 prime_genre
12 sup_devices.num
13 ipadSc_urls.num
14 lang.num
15 vpp_lic

It’s a bit of game of “Where’s Waldo” but it’s in there! There is only one character that needs to be changed in your code for it to work.

Let me know if you’re still stuck and we can work on it together some more.

price = float(row[4]), not 5. Because indexing starts with 0, not 1

You are correct, @reginaa! However, I was really hoping that @simi-1 could find it themselves rather than just give them the answer. Some of the best learning comes from figuring things out ourselves (sometimes with just a little hint!)