以下函数不提供任何输出

时间:2019-09-06 11:46:24

标签: python pycharm

以下函数不提供任何输出。它仅在控制台“以退出代码0结束的过程”中显示以下输出

Python 3.x,Pycharm IDE

def translate(phrase):
    translation = ""
    for letter in phrase:
        if letter in "AEIOUaeiou":
            translation = translation + "g"
        else:
            translation = translation + letter
            return translation
    print(translate(input("Enter a phrase")))

上述功能中预期会出现用户输入提示

1 个答案:

答案 0 :(得分:2)

您的语法错误:

在功能块之外调用函数

def translate(phrase):
    translation = ""
    for letter in phrase:
        if letter in "AEIOUaeiou":
            translation = translation + "g"
        else:
            translation = translation + letter
    return translation

print(translate(input("Enter a phrase")))