i am trying to use codeacademy to learn python. the assignment is to "Write a function called fizz_count that takes a list x as input and returns the count of the string “fizz” in that list."
# Write your function below!
def fizz_count(input):
x = [input]
count = 0
if x =="fizz":
count = count + 1
return count
i think the code above the if loop is fine since the error message ("Your function fails on fizz_count([u'fizz', 0, 0]); it returns None when it should return 1.") only appears when i add that code.
i also tried to make a new variable (new_count) and set that to count + 1 but that gives me the same error message
I would appreciate your assistance very much
inputis already a list. You do not need to nest it inside another list literal.return input.count('fizz')- you don't need to retain a counter around in your fizz_count function. At the moment your function is always going to fall off the end of the function and returnNone...input.countdoes the work for you, it would be more pedagogical to implement it oneself. @user1476390: your implementation needs aforloop, at the very least. Oops, now there's lots of answers that give the whole thing away...ifstatement is a loop now?