List + Functions : Error says: return 1 & None not correct answer


#1
def fizz_count(x):
    count = 0 
    for fizz in x:
        if fizz == "fizz":
           count += 1
           print count
           return count
fizz_count(["fizz","cat","fizz"])

List + Functions : Error is like this: fizz([things i didn't put]] return None instead of correct answer: (the number keeps changing)


#2

You return too early or not at all.


#3

try this

def fizz_count(x):
count = 0
for fizz in x:
if fizz == "fizz":
count += 1
print count
fizz_count(["fizz","cat","fizz"])

don't need to return anything and the print should be aligned correctly


#4

Indentation is essential in Python.

Hi @pkarthicbz ,

Because the code that you posted is not formatted, it is difficult for other users to read and understand it. After code has been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. Alternatively, you can place three backquotes on the line before the code and three backquotes on the line after the code. This will enable us to see important details, such as the indentation and underscores. If you use the backquotes, your code will be color-coded, making it especially easy to read.

Hi @likesobritney ,

See what @ionatan has said, then correct the indentation of your return statement, accordingly.


#5

sorry for that. since that was my first post

thakyou @geomaticmashups

so here's the correct format

def fizz_count(x):
    count = 0 
    for fizz in x:
        if fizz == "fizz":
           count += 1
    print count
fizz_count(["fizz","cat","fizz"])

#6

Hi @pkarthicbz ,

Your function should have a return statement. Change this ...

print count

... to ...

return count

To display the result, change this ...

fizz_count(["fizz","cat","fizz"])

... to this ...

print fizz_count(["fizz","cat","fizz"])