4. Lists + Functions


Hi there.

I have a problem, but I cannot understand where is it.

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

fizz_count(['fizz', 2, 'fizz', 8, 'buzz', 'fIzZ', 'buzz', 1]) returned 1 instead of the correct answer: 2

Could you please help me to figure it out? :slight_smile:


By default, a function returns None at the end of the function. If we want to return something else at the end of the function, we can use the return keyword.

Given return is the last thing a function does, when a return keyword is reached, the function ends

so your function ends after the first fizz is encountered in the list, which i don’t think is desired behavior for your program


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