A Day at the Supermarket 4


#1

Hello Ladies and Gents, Good Morning to you all? I have ran into a problem in my code:

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

This is the error I get:Oops, try again. fizz_count(['fIzZ', 'fizz', 'buzz', 4, 'fizz', 'fizz']) returned 1 instead of the correct answer: 3


#2

your return statement is in the for loop. it needs to be outside


#3

Now it tells me that return is outside function


#4

it should look like this; return statement is outside of for loop, but still inside of the function


#5

OH I see what you mean thank you let's just pray it works!


#6

If it solved your issue flag this thread as solved


#7

It still says the same thing that it is outside the function, I hate it when it does that.


#8

Fixed it I found the error have a nice day!


#9

def fizz_count(x):   #no tab
    count = 0          #one tab
    for f in x:           #one tab
        if f == 'fizz':   #two tabs
            count = count + 1      #three tabs
    return count      #one tab

#10

You Too Sir I had this problem too on a past account