439,941 Members | 1,753 Online Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

# NameError: name 'y' is not defined is a problem i am facing?

 P: 1 #This is to add, sub, mul and div using functions def menu(): print "" print "Welcome to the calculator" print "===== These are some of the options =====" print "1--> for Addition" print "2--> for Subtraction" print "3--> for muliplication" print "4--> for Division" print "5--> To QUIT" return input("Enter any of the above options: ") def toexit(): print "" a=input("Press y to continue or n to exit: ") y=1 print a if a==1: return elif a==0: exit() def add(a,b): print a,"+",b,"=",a+b toexit() def sub(a,b): print a,"-",b,"=",a-b toexit() def mul(a,b): print a,"*",b,"=",a*b toexit() def div(a,b): print a,"/",b,"=",a/b toexit() loop=1 choice=0 while loop==1: choice=menu() if choice==1: add(input("Add this: "),input("to this: ")) elif choice==2: sub(input("Sub this: "), input("from this: ")) elif choice==3: mul(input("Mul this: "),input("with this: ")) elif choice==4: div(input("Div this: "),input("with this: ")) elif choice==5: loop=0 else: loop=0 print "" print "Thank u for using CALCULATOR" --------------------------------------------------------------------------------- Hello All, I am new learner of python, it is really an interesting language.Can u guyz hepl me out. When i run this script, i will enter any one of the option, then enter 2 nos. Then i used the function to ask or prompt for "Do u want to continue Y/N"; there u have to press either "y" or "n". If "y" is pressed the options must be displayed else if "n" is pressed the progarm must exit. Tthe error i am getting is: --------------------------------------------------------------------------------- a=input("Press y to continue or n to exit: ") File "", line 1, in NameError: name 'y' is not defined --------------------------------------------------------------------------------- Can any1 say wht is the problem? Plz giv me the solution. Mar 25 '08 #1 