我有点陷入这个挑战目标是:“创建一个函数来计算句子中有多少个 D”。一些例子:count_d("My friend Dylan got distracted in school.") ➞ 4count_d("Debris was scattered all over the yard.") ➞ 3count_d("The rodents hibernated in their den.") ➞ 3这是我当前的代码:def count_d(sentence): print(sentence) sentence = sentence.lower substring = "d" return sentence.count(substring)当我运行它时,控制台发送一条错误消息:ERROR: Traceback: in <module> in count_dAttributeError: 'builtin_function_or_method' object has no attribute 'count'
添加回答
举报
0/150
提交
取消