Lists + Functions


#1



Lists + Functions


It doesn't return the fizz number but it says that I passed


Replace this line with your code. 

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


#2

Hi @mbeispel ,

Your function does compute and return the correct value, but your print statement follows the return and does not get executed.

Delete the print statement, and instead print the result of calling the function after the function definition.

This should also be outside the function definition ...

x= ["fizz", "dog", "fizz", "pie", "fizz"]

You can pass x as an argument when you call the function.


#3

I am confused what you mean by calling the function after the function
definition and passing x as the argument when you cal the function.


#4

Remove this statement from the function ...

x= ["fizz", "dog", "fizz", "pie", "fizz"]

Place it outside the function. It should not be indented, otherwise it will be part of the function.

Also remove this print statement from the function, as it follows the return statement, and can never execute ...

print count

Then, at the end of your code, the following statement can call the function and display the result ...

print fizz_count(x)

Be sure not to indent that final statement, otherwise it will be part of the function definition.


#5

i have made the corrections but it is still failing, I don't understand what the issue is:

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

x=["fizz", "dog", "fizz", "pie", "fizz"]
print fizz_count(x)


#6

You lost the return statement, so now the function returns None.


#7

Got it. Thanks so much!


#8