Fizz count working but not returning the count on the console


#1

Write your function below!

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

#2

return is not the same as print?

if you want something in the console, use print:

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

this will print the returned count to the console


#3

Okay thank you, I will go back and change it!


#4

I just finished this exercise, if its a return, it's not going to print it out on the console, it just returns a number. What you did wrong on your code was you made a list called x instead of calling the argument, to do that you have to call the def and replace the argument with your list, as so

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

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

hope it helps if you haven't already finished the task :slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.