4/13 is there something obvious im missing?


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

questions:i have triple checked my code there are no indentation errors and such but the error keeps saying that fizz_count(['fuzz', 'fuzz', 8, 'buzz', 'fizz', 'fizz']) returned 1 instead of the correct answer: 2


#2

You may be able to check for indentation errors, but how are we to? Please edit your post, select the code portion and press Ctrl+Shift+C. That will preserve your formatting and let us see what you see.


#3

thank you for the formatting advice! now it looks exactly like it is on my editor but it still is not working...


#4

Try backing off the indentation of the return statement. Get it to line up with for

    for ...

    return count

#5

thank you!!!!! it worked!!!
one quoestion though why do i have to line it up with the for not the if?


#6

So that the loop is able to complete all iterations before exiting the function. We don't want the loop to terminate prematurely before the count is accumulated fully.