Python If, Else, Elif Statements

Screen Link:

My Code:

from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

apps_names = []
for row in apps_data[1:]:
    # Complete the code from here
    
    name = row[1]
    apps_names.append(name)
    print(apps_names[:5])```
Replace this line with your code

What I expected to happen: I was supposed to be given an option to go to the next screen once I submitted the correct answer

What actually happened: “The output of your code didn’t match what we expected.” was the message I got.

Replace this line with the output/error 
``` Tag641```

<!--Enter other details below: -->

Hi
Welcome to the community!!

The print() statement should be placed outside the for loop and correct that and it will give you the expected result.
Hope this helps.

1 Like

like @dash.debasmita said the print() should be outside the for loop, when you print from inside the loop it’d iterate all over, giving you more than the answers requested, what you’re trying to do is to print what you appended in the app_names

2 Likes

Thank you I was wondering what I did wrong but I understand it now

1 Like

I have a h u g e problem with the instruction (nr 2 If statement). My code looks like this:
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])
print(rating)

price = float(row[4])

if price == 0:
    free_apps_ratings.append(rating)

avg_rating_free = sum(free_apps_ratings /
len(free_apps_ratings)

What am I doing wrong? What’s the correct code?

1 Like

Hi @unicornlady007,

Welcome to the Community! :tada:

You have the following issues to fix:

  1. You forgot the closing brackets in sum(free_apps_ratings)
  2. Put the whole last piece of code on the same line:
avg_rating_free = sum(free_apps_ratings) / len(free_apps_ratings)

or, alternatively, use the code line break symbol \:

avg_rating_free = sum(free_apps_ratings) / \
len(free_apps_ratings)

Also, I’m not sure about your indentation since I can’t see it from your code. And the indentation can also cause issues. For your future technical question, please follow these guidelines.