I am trying to count the word fizz using python. However it is giving me an error.
def fizz_count(x):count =0
for item in x :if item== "fizz":count=count+1
return countitem= ["fizz","cat", "fizz", "Dog", "fizz"]example= fizz_count(item)print example
i checked with indentation but still it does not work. Where i am doing wrong?
Your indentation seems to be incorrect, and you should not have the first return count
(why would you return count
as soon as you define it??).
def fizz_count(x):count = 0for item in x:if item == "fizz":count += 1 # equivalent to count = count + 1return countitem = ["fizz", "cat", "fizz", "Dog", "fizz"]example = fizz_count(item)print example