Python for loop error

前端 未结 3 1186
盖世英雄少女心
盖世英雄少女心 2021-01-28 17:38

I\'m working on a Python exercise at Codecademy and got stuck on what looks like a simple problem:

Write a function fizz_count() that loops t

3条回答
  •  走了就别回头了
    2021-01-28 18:21

    You are passing in a list ['fizz', 'buzz']) so i is equal to fizz or buzz not an integer. Try if i =="fizz"

    def fizz_count(x):
      count = 0
      for i in x:
        if i  == 'fizz': # i will be each element in your list
          count = count + 1
      return count
    

提交回复
热议问题