我有點陷入這個挑戰目標是:“創建一個函數來計算句子中有多少個 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
提交
取消