List and Functions


#1

I already look through the other topics but didn't find a answer -

First - why doesn't work the code and how can I fix it?
and second if I insert fizz_count = (["fizz","cat","fizz"])" before the return count it doesn't show me an error but there is no output.Why?

Many thanks!

ERRORMESSAGE: Oops, try again. fizz_buzz doesn't look like it is a function!

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

#2

GET IT - can someone explain me why?
Thanks.

def fizz_count (x):
    count = 0
    for item in x:
        if item == "fizz":
            count = count + 1
    return count
    
result = fizz_count (["fizz","cat","fizz","Fizz","fizz"])

print result

#3

Hi @irenekb,

This statement, from your original post, assigned a list to the name fizz_count ...

fizz_count = (["fizz","cat","fizz"])

Thereafter, that name no longer referred to the previous function definition that you wrote.

In your second try, you correctly called the function and displayed the result ...

result = fizz_count (["fizz","cat","fizz","Fizz","fizz"])

print result

#4

Ah - okay it was like overwriting, or?

Many thanks!


#5

Yes, after your function definition, the name fizz_count referred to a function. You then assigned a list to that name, overwriting the original reference to the function. Then, when Codecademy tested your code, it found that the name fizz_count did not refer to a function. That accounts for the message that you received.


#6

Thank you a lot for your help!


#7

A post was split to a new topic: Problem with fizz_count


#8