11. count


#1

Not sure why it's counting 1 when I specifically said if item is in sequence. Maybe I should be adding a range to the function?
Oops, try again. Your function fails on count([1],7). It returns 1 when it should return 0.

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

#2

this will loop over sequence, and for each item in sequence increase found by one.

loop over sequence, check if the item in the list equals item (your function parameter)


#4

Getting some getitem error now

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

#5

???

Really stuck on this one.


#6

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