Lists + functions


#1

Write your function below!

def fizz_count(x):
count = 0
for item in x:
if item == 'fizz':
count = count + 1
return count

result = fizz_count(['fizz', 'fizz', 4, 4, 'fuzz', 'fizz', 8])
print result

What am i doing wrong :\


#2

Hi you should tell us the error you got..


#3

oh sorry,

Oops, try again. fizz_count(['fizz', 'fizz', 'fizz', 1, 'fizz', 8, 4]) returned 1 instead of the correct answer: 4


#4

it could be an error of indent ...does your code look like that?

def fizz_count(x):
    count = 0
    for item in x:
        if item == 'fizz':
            count = count + 1
    return count

result = fizz_count(['fizz', 'fizz', 4, 4, 'fuzz', 'fizz', 8])
print result

#6
# Write your function below!
def fizz_count(x):
    count = 0
    for item in x:
        if item == 'fizz':
            count += 1
        return count

result = fizz_count(['fizz', 'fizz', 4, 4, 'fuzz', 'fizz', 8])
print result

yeh


#7

look well your

return count

where is it and see on the code I post earlier.. ..


#8

i'm dumb -.- fml, thanks good sir!


#9

ok !! read the code and try to understand aways before copy,paste a running it!!!

def fizz_count(num):
count = 0
for x in num:
if x == "fizz":
count = count + 1
return count

word = ["izz","cat","fizz","fizz","cat","fizz"]
num_f = fizz_count(word)
print num_f


#10

the result is 0, why? My code is same as yours.


#11

Hi All,

My first post in the forum.So wishing you all a great time.I am new to python & code academy.I am a retired public health doctor.Learning to code as hobby.

I am also stuck at the fizz_count function.But the following code works in other editors(like PYCharm)..It gives the result as 2.But here it gives the error message is:=Oops, try again. fizzcount(['fizz', 'buzz']) returned 2 instead of the correct answer: 1._
But I think the correct answer is 2.
I am stuck here and cant't proceed.Please help...

(this code works in other editors)
def fizz_count(x):
count=0
for things in x :
if things=="fizz":
count +=1
print(count)
return count
x=["fizz","cat","fizz"]
fizz_count(x)

cheers

PKJ


#12

def fizz_count(x):
count = 0
for item in x :
if item == “fizz”:
count = count + 1
return count
this is actually the correct code
hope it helped


#13

Sorry perhaps already replied. But seems related to identation