Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python—将两个函数添加到一起_Python - Fatal编程技术网

Python—将两个函数添加到一起

Python—将两个函数添加到一起,python,Python,处理一个问题集-以下是问题: 两个函数定义保存在同一文件中: 函数count_元音有一个参数,即一个单词,并返回该单词中元音的数量。 函数count_consonates有一个参数,即一个单词,并返回该单词中的辅音数。 要确定单词中的字母数,请为调用count_元音和count_辅音的以下函数编写一行正文: def count_letters(word): """ (str) -> int Return the number of letters in word. >>>

处理一个问题集-以下是问题:

两个函数定义保存在同一文件中: 函数count_元音有一个参数,即一个单词,并返回该单词中元音的数量。 函数count_consonates有一个参数,即一个单词,并返回该单词中的辅音数。 要确定单词中的字母数,请为调用count_元音和count_辅音的以下函数编写一行正文:

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())

错。为什么?

你知道它应该是
count\u元音(string)+count\u辅音(string)
而不是
你不需要调用
count\u字母
,只需要调用另外两个函数。您还需要将
word
参数传递给每个函数

return count_vowels(word) + count_consonants(word)

count\u元音或count\u辅音返回什么?没有
count\u字母的
count\u元音(foo)+count\u辅音(foo)
有什么问题吗?@tcaswell你读过问题了吗?如果你读了这个问题,很明显他们会返回什么。@SethMMorton苏格拉底方法你缺少函数参数。显然他们不知道,否则他们不会问。