python中未定义的变量 [英] variable not defined in python
本文介绍了python中未定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是python编程的新手.我正在启动我的第一个程序,但遇到了一些麻烦..是否有更好的方法来执行下面的代码片段?当我运行程序时,我得到"yes_no"未定义.
Hi I'm very new with programming in python. I'm starting my first program but i'm having a little trouble.. is there a better way of doing the snippet of code below? When i run the program I get "yes_no" not defined.
def main():
print "\n Welcome to registration. Are you an authorized user?\n"
yes_no = raw_input("Yes or No?: ")
if yes_no in ("Yes", "yes"):
return oldUser()
elif yes_no in ("y", "Y"):
print ("Please enter YES")
return wrong()
elif yes_no in ("n", "N"):
return wrong()
else:
print ("\n Unauthorized text!\n")
return main()
def wrong():
if yes_no in ("y", "Y"):
print ("Please Enter Yes!")
return main()
else:
yes_no in ("n", "N")
print ("Please Enter No!")
return main()
推荐答案
yes_no未在errors()方法中定义,因此仅在main()中可见.您可以像错误(yes_no)一样将yes_not传递到错误()中
yes_no is not defined in wrong() method, so it is only visible in main(). You can pass yes_not into wrong() like wrong(yes_no)
这篇关于python中未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文