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 is not defined in wrong() method, so it is only visible in main(). You can pass yes_not into wrong() like wrong(yes_no)