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.

sum isnt given in the previous lectures. i am on the data science track. if that was given i would be able to solve the problem.

i didnt want to look at the answer but i had to.

avg_rating_free = sum(free_apps_ratings) /
len(free_apps_ratings)

1 Like

Hi @starkid614,

Welcome to the Community!

The sum() function was introduced in the previous lesson, Python For Loops, Screen #9:

Use the sum() function to add all the ratings (to be able to use sum(), we’ll need to store the ratings as floats or integers).

Here is the link to the screen:

Happy learning! :mortar_board:

Good morning @Elena_Kosourova I need guidelines on posting in the community. I seem to have been looking for the pane to share some difficulty and enlightenment I really wanted to get

1 Like

Good day! Sorry I have similar issues

The indentation I guess it’s right but it keeps saying free_apps_ratings not defined.

Pls I need help

1 Like

Hi Jerry,

Welcome to the Community!

About the guidelines on posting in the Community, please refer to this post:

This post contains a lot of useful links, and I encourage you to explore all of them (of course, not today altogether, take your time). However, since you’re asking exactly about how to post in the Community, consider exploring first these 3 links from that post, as per the screenshot below:



By the way, you can always easily find the post Start Here - How to Use the Community for any further reference by clicking the Start Here button in the top-right part of the Community, as follows:

Happy learning! :mortar_board:

1 Like

Jerry,

Your indentation is correct, but you have a typo in the end of your code. It should be len(free_apps_ratings) instead of len(free_apps_rating). Please fix it, and your code will work fine.

1 Like

Wow! Am grateful thanks so much for your reply. I can now proceed with the learning. It worked perfectly

1 Like

Thanks so much. This will be really helpful

1 Like