4. List + Functions


#1



Help me; Whats wrong with my code?

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


#2

Hi, @berivan28 ,

What effect does this have on the value of count? ...

count += count

#3

that means count = count + count?


#4

Yes, it is equivalent to ...

count = count + count

So, since count starts out at 0, what happens the first time the statement is executed?


#6

Not sure how to get the indents to work correctly in the post.
But, the code wasn't finished.

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

#7

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