List + Functions...am stuck pls


#1

I get the error message File "python", line 8
SyntaxError: 'return' outside function
when I run the code below.
Someone please help

# Write your function below!
def fizz_count(x):
    count = 0
for item in x:
    if item == "fizz":
        count = count +1
    fizz_count(["buzz","fizz"])
    return count

#2

This is the line that calls the function, but your code has it inside the function.


#3

I just switched the code, i still get same error message. Please can you paste the right code to run in clear terms. Forgive my ignorance


#4

After formatting your opening post, we can see that the for loop is not inside the code block.

def fizz_count(x):
    count = 0
for item in x:               # indent 4 spaces
    if item == "fizz":       # indent 4 more spaces
        count = count +1     # indent 4 more spaces
    return count

fizz_count(["buzz","fizz"])  # moved out function body

#5

thank you @mtf for your immediate response. below is the link of the page. I just copied your code and got same error mesage.
https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096.


#6

Did you correct the indentation as noted?


#8

yes, thank you. It works now.


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.