I am new to Python, and I encountered a NameError: name 'raw_input' is not defined exception from this code:
input = raw_input('Start over? Y/N: ')
if input == 'N':
done = True
How can I fix this?
Three answers:
om
2009-05-05 16:14:53 UTC
Most likely you are using Python 3, which is not completely compatible with Python 2. One of those incompatible changes is that the Python 2 'raw_input()' function has been removed. What you have there is a Python 2 program but you're trying to use Python 3 to run it, hence the error.
You can either change your program so that it becomes acceptable to Python 3 (change 'raw_input(...)' to 'input(...)' and pick a new name for the variable that receives the user's value) or you can download Python 2 and use that to run your program.
Switching to Python 2 is probably the best way to go, because almost all of the Python tutorials and examples you'll find on the net and almost all of the answers that you'll find by searching Yahoo Answers are written for Python 2. Python 2 is still actively maintained because Python 3 is still kinda experimental.
If you decide to stick with Python 3 then you should familiarise yourself with the things that have changed incompatibly so that you'll recognise them and know what to do when programs fail like this. Follow the link below for a summary of what's different in Python 3.
Greta
2016-05-09 08:27:30 UTC
I'm having trouble to with a def statement in python 3. Its something like this. def initloop():
countloop = 0
def exe(count):
while countloop != count:
countloop = countloop + 1
else:
x = "go"
count = 0
Whats wrong? Is a def inside a def illegal?
nexus
2015-11-27 13:08:12 UTC
thnks that helps
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.