不明白为什么我的函数没有被调用

时间:2018-10-07 19:44:13

标签: python function call

print ("Hello, User :)")
def search():
    answer = phrase.find(search)
    return answer

y = "Y"
while y == "Y":

    phrase = input("Please enter a phrase any phrase: ")
    print ("Thank you User - the phrase you entered reads as follows: ")
    print (phrase)

    search = input("Please enter one of the words of the phrase you just entered, or some consecutive characters from that phrase, and I will search for them: ")
    print ("Thank you, User")
    print ("Your word or characters are located at the following index location: ")
    search()
    #print (answer)

    y = input("Thanks for playing.  Would you like to play again(Y/N)?: ")
else:
    print ("Goodby, User")

希望某人可以帮助为什么无法调用我的函数定义。

1 个答案:

答案 0 :(得分:0)

函数名称不能与变量名称相同。只需像这样更改search变量名:

search_ = input("Please enter one of the words of the phrase you just entered, or some consecutive characters from that phrase, and I will search for them: ")

search()

如果您希望打印结果,请调用以下函数:

print(search())