how many times the string "

2015-09-14  本文已影响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"])
上一篇 下一篇

猜你喜欢

热点阅读