根据报错对上述代码进行修改
以下是修改后的代码:
def my_count(num_list, target):
count = 0
for num in num_list:
if num == target:
count += 1
return count
test_list = [1, 2, 3, 4, 2, 2, 3]
test_target = 2
result = my_count(test_list, test_target)
print(result)
修改说明:
- 在函数定义时添加了参数
num_list和target,以便在函数内部使用。 - 在函数内部使用了
num_list和target,而不是list和target。 - 修改了
return count的缩进,使其成为函数my_count的返回值。
原文地址: https://www.cveoy.top/t/topic/bhPG 著作权归作者所有。请勿转载和采集!