Guys help me in Lists and Functions


#1

I dont know whats wrong

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

           print c

***********the above code gives an error like printed 1 instead of correct answer 3, sometimes 4, sometimes 2


#2

the function call + print:

           c = fizz_count(["fizz", "fizz", "fizz"])

           print c

should be outside the function (hint: indention, or rather, no indention)

here:

count = count + 2

why +2? when the if condition is true, only one match is found, so you should be increasing count by one, not two

finally, this:

return count

a function ends the moment a return keyword is reached, this is currently happening when one fizz is found, place the return outside the for loop (hint, again, your indention is off)

if you need more help, post an updated version of your code


#3

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

print c

here you go, still the same, i already tried everything


#4

count = count + 0

now you increased the count by zero.

and this step:

you skipped altogether.


#5

Awesome man, awesome, now I understood, I was dumb, prost mate, drink a beer tonight from my side :wink:)))))))


#6