Code works but the website says it doesn't


#1




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

The code works fine. The website (incorrectly) says it doesn't. I just want to move on to the next exercise.


# Write your function below!
def fizz_count(count):
    count = 0
    
    for item in x:
        if item == "fizz":
            count = count + 1
    return count
    
x = (['buzz', 'fuzz', 'fizz', 1, 'fizz', 'fIzZ', 'fizz'])
fizzcount = fizz_count(x)
print fizzcount


#2

but if i now would create another list, and call the function again:

def fizz_count(count):
    count = 0
    
    for item in x:
        if item == "fizz":
            count = count + 1
    return count
    
x = (['buzz', 'fuzz', 'fizz', 1, 'fizz', 'fIzZ', 'fizz'])
fizzcount = fizz_count(x)
print fizzcount
y = ['fizz','buzz','buzz']
print fizz_count(y)

The wrong result would be printed (hold on, the wrong number will not even be printed, you will get an error), which is why the exercise is preventing you from progressing.

this line:

for item in x:

x is the list outside the function, i would use the list you pass into the function (count), except you set that to 0. I would rename the function parameter:

def fizz_count(total):

and then do:

for item in total:

this way, you loop over the list passed into the function