4. lists and functions help


#1

here is my code, it keeps counting wrong.

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


#2

First of all, "quote" your code so it will be clear for others.
Your code seem to be good, but check indentation

my code looks like that and i passed.
def fizz_count(x):
count = 0
for lol in x:
if lol == "fizz":
count = count + 1
return count


#3

for some reason quote dont work :frowning:


#4

Hi, you need to be really accurate with the spacing and positioning of the text, here's working example:

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

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


#5

"def fizz_count(x)
count = 0
for item in x:
if item == 'fizz':
count = count + 1
return count"
doesn't appear to working for me, the error that comes up says "None" is returned in place of "0" if the list doesn't have 'fizz' and "1" is returned if 'fizz' appears more than once.

What am I missing to get it to read more than just a yes or no?


#6

you need crete a list like : fizz_count(["fizz","cat","fizz"])


#7

why i still get 0 not 1 ???


#9

you need to be very accurate with indentation. that's probably the only reason why your code doesn't work.


#10

Here is an example of a successful solution.<
I was getting hung up on not indenting count = 0. Everything has to fall under count = 0 in order for the code to work.


#11

`# Write your function below!
def fizz_count(x):
count = 0
for key in x:
if key == "fizz":
count = count + 1
return count

hej = ["fizz", "eye", "fizz"]
god = fizz_count(hej)
print god`


#12

if item == 'fizz':

return count"

must be same spacing


#13

This is working / right;

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

#14

You must add tabulation in code, your programm can't read code if all strings will be stand in a row. Press TAB button in some places and code will work.