Lists + Functions


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

returns as an error
fizz_count(['fizz', 'buzz']) returned 0 instead of the correct answer: 1


#2

@francuccio99,

Check this line out …

        if x == "fizz":

To what does x refer? Consider what is the parameter of the fizz_count function. Also consider the role of item in the for loop.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.