Count occurrences
Loop through an array and count how many elements match the condition.
def count(array, target):
count = 0
for i in range(len(array)):
if array[i] == target:
count = count + 1
return count
def count(names):
count = 0
for i in range(len(names)):
if names[i] == "Jane":
count = count + 1
return count
def count_teens(ages):
count = 0
for i in range(len(ages)):
if ages[i]>=13 and ages[i]<=19:
count = count + 1
print("There are", count, "teens")
def count(pupils):
count = 0
for i in range(len(pupils)):
if pupils[i].name == "Jane":
count = count + 1
return count