我有点陷入这个挑战
目标是:“创建一个函数来计算句子中有多少个 D”。
一些例子:
count_d("My friend Dylan got distracted in school.") ➞ 4
count_d("Debris was scattered all over the yard.") ➞ 3
count_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_d
AttributeError: 'builtin_function_or_method' object has no attribute 'count'
慕神8447489
HUX布斯
相关分类