Unable to understand lists+functions


#1

Hi All,

I am stuck at the following exercise:

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096
I'm getting an error message : "File "python", line 9
SyntaxError: 'return' outside function"

I had written the following piece of code:

def fizz_count(x):
    count = 0
for item in x:
    if item == "fizz":
        count = count + 1
    
return count

Please tell me where am I doing a mistake.

Thanks.


#2

There are some issues... lets take a look :slight_smile:

So, you're getting an error

That is because return is outside of your function. Your function can't loop through x because x is not defined. So, it seems like you've forgotten to indent somethings after line 2 of your code. How should we fix that? How do we get x to not to give us an error? :wink: hint: I mentioned what to do in this post.


#3

Thanks so much..I totally screwed up the indentation. Now it's working. :slight_smile:


#5