晚上好。我的功能有问题。我有4到5种不同的菜单 我想从main调用Usermeny(),并生成if,elif语句 如果选择==1:做点什么。你知道吗
但是当我选择1时,我得到了一个错误“NameError:global name'Choice'is not defined”
如果我在Usermeny函数中添加全局选项,我可以从main调用它,但我认为我的返回可以工作吗?你知道吗
我的主要功能是
def main():
TRIES=25
Usermeny()
if Choice==1:
DOSOMETHNIGHERE
用户菜单是这样的
def Usermeny():
while True:
try:
global Choice
Choice=(int(input("What would you like to do: ")))
except ValueError:
print("You have to choose a number in the meny")
continue
if not Choice in range(1,5):
print("You have to choose a number in the meny")
continue
return Choice
删除全局声明,这是不需要的。你知道吗
将
Usermeny
函数的结果赋给main函数中的Choice
:相关问题 更多 >
编程相关推荐