11. Count


#1



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

Hi! Sorry for posting, but I'm stuck. Not quite sure what else to add, and where I am missing information. Any tips? Thanks in advance!


Oops, try again. Your function fails on count([1], 7). It returns None when it should return 0.


def count(sequence, item):
    found = 0
    sequence = []
    for character in sequence:
        if character == item:
            found += 1
            return found
    print count


#2

you want to count the numbers of item in a list, for this you use a loop

then after the loop, you want to return the number of items found


#3

You have two independent problems:
The first: Think about your conditional statement. It checks weather the character in the sequence is item. If it is, it adds one to found.
What happens next? And what is with the next character in sequence?

Second:count([1], 7) litteraly means:
execute the function count with the variables sequence=[1] and item=7. For this define a new variable, call it found and set it to zero...

Don't hesitate to ask, if you need further help.
Greeting Kiluahh


#4

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