0

Here's my code:

name = input("What's your name? ")
print("Nice to meet you " + name + "!")

But when i enter a name, for example "john", it gives me this error:

Traceback (most recent call last):
  File "name.py", line 1, in <module>
    name = input("What's your name? ")
  File "<string>", line 1, in <module>
NameError: name 'john' is not defined

The version of python i'm using is "2.7.10".

2 Answers 2

2

You need to use raw_input rather than input, as the latter attempts to evaluate what you enter while the former keeps it as a string.

Sign up to request clarification or add additional context in comments.

Comments

2

One of the problems with Python 2 is that it tries to take user input from the input function and execute it as Python code, instead of just returning it as a string. To avoid this problem, use raw_input instead:

name = raw_input("What's your name? ")

1 Comment

Thanks, First Time I Hear Of raw_input()!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.