Python lists+functions

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容