美文网首页
how many times the string "

how many times the string "

作者: 帅灰 | 来源:发表于2015-09-14 09:53 被阅读121次

Write a function that counts how many times the string "fizz"
appears in a list.
Write a function called fizz_count
that takes a list x
as input.
Create a variable count
to hold the ongoing count. Initialize it to zero.
foreachitem in x:, if
that item is equal to the string "fizz"
then increment the count
variable.
After the loop, please return
thecount
variable.

For example,fizz_count(["fizz","cat","fizz"])
should return 2.

def fizz_count(x):
    count = 0
    for y in x:
        if y == "fizz":
             count = count + 1
    return count

fizz_count(["fizz","buzz","fizz"])

相关文章

网友评论

      本文标题:how many times the string "

      本文链接:https://www.haomeiwen.com/subject/iotmcttx.html