Help


#1

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

WHAT DO YOU WANT FROM ME CODECADEMY!?!?!?!??!?!?!!?!??!?!?!?!?!?!??!?!?!?!?!?!?!?!?!??!?!!??!?!?

`


#2

Oops, try again. fizz_count(['fizz', 'fizz', 1, 'fizz', 7, 'fuzz', 10, 'fIzZ']) returned 1 instead of the correct answer: 3

this is what it tells me.


#3

a function ends the moment a return keyword is reached, if a return keyword is reached in the loop, the loop will break

count the number of fizz inside the loop, then after the loop return the count


#4

Try using a discrete iterator variable...

for n in x:

#5

ive tried that - i took the "return" out of the variable, but it gave me an error message saying it has to be inside a function: File "python", line 12 SyntaxError: 'return' outside function


#6

you have to place the return inside the function but outside the loop? Can i see how you did this?


#7

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

#8

I have been on this one for like a month now, i am honestly considering breaking my computer now.:rage:


#9

the indent of return count should match the indention level of your for loop. This way, its inside the function but outside the loop


#10

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

    elif item != "fizz":
        count = count

        return count

like this?


#11

Nvm my friend just helped me. Im kind of mad now cause the error was so simple...:expressionless:


#12

But thank you @stetim94 your answer was correct i just had it wrong...


#13

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