Count 11/15


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/1?curriculum_id=4f89dab3d788890003000096#


def count(sequence , item):
    total = 0
    for item in sequence:
        total += 1
    return total


I need help finding how to get item, i know how to do the rest, could you guys help me?


#2

I know what I need to do, item = something to find the item


#3

you could loop over the items in sequence:

for x in sequence:

then you could an if statement to check if x equals item, if so, increase total by one.


#4

oh yea, thanks :slight_smile:


#5

aw doesn't seem to work, here's my code:

def count(sequence , item):
    total = 0
    for x in sequence:
        if item == x:
            total += 1
        return total

#6

you got pretty close. the problem is that a function ends the moment a return keyword is reached, which happens in the first run of the loop in your case.

Maybe you should change the indent of return so that return is reached after the for loop had a change to loop over all items in sequence?


#7

yeah yeah i just realised it a second before u posted it XD


#8

Thanks anyway dude :smile:


#9