-1

Whenever I try to execute this code:

name = input("What's your name?")
print("Hello World", name)

By running the command python myprogram.py on the command line, it gives me this error:

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

It asks me the name but as soon as I type it and press enter it crashes, what does the error mean? Thanks.

kichik
  • 33,220
  • 7
  • 94
  • 114
overmach
  • 96
  • 2
  • 11

2 Answers2

1

In Python 2 you should use raw_input instead of input in this case.

Julien Salinas
  • 1,059
  • 1
  • 10
  • 23
0

Assuming you are using python 2 when you enter just (John) it interprets that as variable. You will either need to enter ("John"), forcing it to see a string, or use name = raw_input() in the first line.

Isaac Little
  • 36
  • 1
  • 7