for example
def count_small(numbers):
total = 0
for n in numbers:
if n < 10:
total = total + 1
return total
lost = [4,8,15,16,23,42]
small = count_small(lost)
print small
练习
写一个functin数“fizz”出现在一个列表中多少次
1 写一个 function called ****fizz_count that take a listx as input.
2创建一个变量count 去计数,设置初始值为零
3foreachitem in x:,if that item 等于“fizz”,然后increment the count
4after the loop ,please return the count
def fizz_count(x):
count = 0
for item in x
if item == “fizz”:
count = count + 1
return count