11/15 Count Clarifying question on for loop


#1

Does this code not work because “item” is a single number, and not a list?

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

return total


#2

Correct. Check if item is in sequence, and how many times it occurs.


#3

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