Lists + functions


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096


can't really see why this code isn't working. when i run it, it shows 'Oops, try again. fizz_count(['fizz', 'buzz']) returned 0 instead of the correct answer: 1'

any help would be appreciated as i've been stuck on this excersise for a while now.


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


#2

count == count + 1

== is a conditional operator.
It does not save something inside left of the variable but its used to compare and return booleans.

To do so we have operator called assignment operator = .
It save or sticks value to left of the variable.
for ex..

x = 4

and here we are saving the frequency of fizz to count variable.


#3

thanks for that, it works now. and thanks for explaining why this is the case.


#4

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