Lists+ functions


#1

what is the error in this ?


#2

Your indent level (the amount of spaces) doesn't match anything. You want the return the be at the same indent level as your for loop


#3

When the Codecademy says about a list called x, they mean that you have to make a list that includes whatever you want, but it needs to have a 'fizz' in it. That's the problem.


#5

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

need some help here, can someone show me what they wrote? I am beyond stuck


#6

Your return count should be at the same indent level as your for loop, if you don't do this, the for loop will only run once (since then return is reached in the first run of the loop, the function ends), you can see this effect if you add a print statement and a function call:

def fizz_count(x):
    count = 0
    for item in x:
        print "i get executed"
        if item == "fizz":
            count = count + 1
        return count
print fizz_count(["fizz","fizz"])

note: this code has wrong indent as you can see, the loop only execute once


#7

thank you very much i got it to run


#8

i found it's helpful. Thanks a lot


#10