4/13 code works, but error message nonetheless


#1


https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096#

Oops, try again. fizz_count(['fizz', 'buzz']) returned 3 instead of the correct answer: 1


I dont get a few things. First: I didnt give the input 'fizz','buzz' so why does it give an error on that?
It changes to different errors for different lists, even if I dont change anything in the code. So it seems to be running through lists which are in the program to check whether the code works.

But in the console it returns it correctly. I tried with many different lists and it always works fine, even with numbers in them.
So what exactly is wrong here?
Thanks for your help

update: tried to refresh browser, to no avail


# Write your function below!

def fizz_count(list):
    count = 0
    for item in x:
        if item == 'fizz':
            count += 1
    return count 
    
x = ['fizz', 'fuzz', 'fizz', 'fizz']
counter = fizz_count(x)
print counter 


# ['fizz', 3, 1, 6, 'fizz'] returned 1 instead of the correct answer 2
#(this is also not true, it returned 2 in the console)


#2

we can recreate the problem:

def fizz_count(list):
    count = 0
    for item in x:
        if item == 'fizz':
            count += 1
    return count 
    
x = ['fizz', 'fuzz', 'fizz', 'fizz']
y = ['fizz', 'buzz']
z = ['fizz', 3, 1, 6, 'fizz']
print fizz_count(x)
print fizz_count(y)
print fizz_count(z)

your function should work for all this lists, currently it only works for one.


#3

Aaah, I got it, thank you!
x -> list
and it works just fine :slight_smile:


#4

you do understand how the arguments (x, y and z) are copied into the function parameter (list), allowing function to do repetitive work?


#5

Now I do, yes. At first I didnt get your reply but after a min of thinking it clicked and with that also the understanding of why (list) is necessary there to make it a general funktion in which any given list would work, not only x.


#6