A day at the supermarket. lists and functions


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096#


File "python", line 7
SyntaxError: 'return' outside function


Why does it keep calling return an "outside function?"
I've been trying to fix this for a while. Can someone help me please?


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


#2

This does not compute. x is not defined, so will raise an error. The line is not needed since you have a count variable (that doesn't need brackets).

Generally speaking, we should avoid dressing up values with unneeded brackets (parens).

If you want the loop to complete iterating, move the return to the left four spaces so it lines up with for.


#3

it still doesn't seem to work.
here is what I put in

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

did I get something that you said wrong?


#4

The top line looks like it should be a function name.

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

#5

thanks that worked!
I gotta have 20 characters for it to allow me to post this and I don't know what else to write so I wrote this line.


Lists + Functions. Can't see where I'm going wrong!
#6

Thanks, this helped a lot.