0

So I'm learning python, from a java background, for my new job, and I've run into the following error.

I tried running this module on the terminal (using mac), then through IDLE. All futile.

 userName = input("What is your name?: ")
 lengthName = str(len(usernName))
 yourName = "\nYour name is " + userName + " and is " + legnthName + " letters long."
 print(yourName)
 input("\nPress enter to exit")

When this is executed in the terminal and I type for the first input : "John" I get this as a result:

 File "[...]", line 1, in <module>
 userName = input("What is your name?: ")
 File "<string>", line 1, in <module>
 NameError: name 'John' is not defined

Similarly, when executed via IDLE:

 Traceback (most recent call last):
 File "/Users/zachmartin/Desktop/python fails/lol.py", line 2, in <module>
 lengthName = str(len(usernName))
 NameError: name 'usernName' is not defined

What's going on here?

asked Mar 27, 2013 at 18:50

1 Answer 1

4

Two problems:

  • You should be using raw_input() rather than input() (because input() will treat what you type as Python code and try to evaluate it).

  • You have a typo, userName vs. usernName (note the extra n). (Also legnthName later on.)

answered Mar 27, 2013 at 18:51
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.