Count - Practice Makes Perfect

#1

Please, help! I am trying to get my head around the string methods, but it feels like I am missing out on something.

I tought this is one way to solve the "Count"-exercise:

``````def count(sequence,item):
number=[]
for i in sequence:
if i==item:
number +=1
else:
number = number

count``````

But it did not
Oops, try again. Does your count function take exactly two arguments: a list and an item to check against that list? Your code threw a "'int' object is not iterable" error.

I can better ask for some help... I thought that I made a function with two arguments, Γ‘nd that I turned the string into an integer.
Can anybody help me finding out what section of the course I did not understand?

#2

lets add a function call so we can see interpreter error:

``````def count(sequence,item):
number=[]
for i in sequence:
if i==item:
number +=1
else:
number = number
print count([1,2,3], 1)``````

`number` is a list, then you try to get the sum of list and 1, how does that work?

Why not make number an actual number (integer) which you can increase by one each time a match is found

#3

Thank you, Stetim94! I guess I should have thought about that...