problem with a simple code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: problem with a simple code (/thread-4676.html) |
problem with a simple code - hello_its_me - Sep-02-2017 Hi, I am new to python and I am trying out some things in python and wanted to experiment a bit with while as loop but I keep getting this error "Traceback (most recent call last): File "testing.py", line 4, in <module> choose = input("go on (y) or stop (s)") File "<string>", line 1, in <module> NameError: name 'y' is not defined " I am able to run the code but when I enter my selection it gives me the error. Is it because if I set a string once it is "forever" and I can't change it again? If it is like that how can I fix it? Thanks loop = 1 while loop == 1: choose = input("go on (y) or stop (s)") if choose == "y": print("ok") loop = 1 if choose == "s": print("See you next time") loop = 0 RE: problem with a simple code - metulburr - Sep-02-2017 You are using a python2.x intepreter with python3.x code. Either change input to raw_input or use a python3.x intepreter. I would suggest the latter as python2.x is pretty much on its death bed. as a preference i would write it like this. Mainly because its more readable. done = False while not done: choose = input("go on (y) or stop (s)") if choose == "y": print("ok") elif choose == "s": print("See you next time") done = True RE: problem with a simple code - hello_its_me - Sep-02-2017 well that was a terrible mistake than thanks a lot!!! RE: problem with a simple code - metulburr - Sep-02-2017 dont worry about it. It happens a lot. |