Lists+Functions


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/lists--functions?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
fizz_count([6, 8, ‘fuzz’, 3, ‘fizz’]) returned 0 instead of the correct answer: 1

<What do you expect to happen instead?>
It should return the correct value


x=["fizz","kizz","fizz","buzz"]

def fizz_count(x):
  n=0
  for word in x:
    if word=="fizz":
      n=n+1
    return n.

#2

a function ends the moment a return keyword is reached

so, your function ends in the first iteration of the loop (thanks to the return keyword), but to count all the fizzes in the list, the loop needs to make all its iterations.


#3

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