【发布时间】:2016-04-30 05:10:58
【问题描述】:
我在 while 循环中有以下代码:
while True:
user_input = input("y or n")
if user_input == "y":
yes()
break
if user_input == "n":
no()
break
def yes():
print("yes")
def no():
print("no")
当我输入“y”时,会出现此消息,阻止函数执行。
NameError: name 'yes' is not defined
这是为什么?我该如何解决?
【问题讨论】:
-
在while循环之前定义yes()
-
道歉,但是提供什么理由将我的帖子的分数降低到-1? @TimCastelijns 你知道吗/
-
可能是因为这是基本的并且之前已经问过
标签: python function input while-loop