-2

問題セットに取り組んでいます-これがQです:

2 つの関数定義が同じファイルに保存されます。関数 count_vowels には 1 つのパラメーター (単語) があり、その単語の母音の数を返します。関数 count_consonants は 1 つのパラメーター (単語) を持ち、その単語の子音の数を返します。単語の文字数を決定するには、count_vowels と count_consonants の両方を呼び出す次の関数の 1 行の本文を記述します。

def count_letters(word):
""" (str) -> int

Return the number of letters in word.
>>> count_letters('hello')
5
>>> count_letters('bonjour')
7
"""
# Write the one-line function body that belongs here.

私の答え:

return count_letters(count_vowels() + count_consonants())

違う。なんで?

4

2 に答える 2

3

を呼び出す必要はありませんcount_letters。他の 2 つの関数を呼び出すだけです。wordまた、各関数に引数を渡す必要があります。

return count_vowels(word) + count_consonants(word)
于 2013-09-04T02:49:38.233 に答える
0

代わりにそうすべきだと知っていましたcount_vowels(string) +count_consonants(string)か?

于 2013-09-04T02:49:27.247 に答える