Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

I'm brand new and playing around with Python. I entered this code: person = input('Enter your name: ') print('Hello', person) and this happens: >>> person = input('Enter your name: ') print('Hello', person) Enter your name: Sarah Traceback (most recent call last): File "", line 1, in person = input('Enter your name: ') File "", line 1, in NameError: name 'Keely' is not defined >>> What is going on? Why won't it print "Hello, Sarah?"

OpenStudy (rsmith6559):

Using input() in this context is Python 3 syntax. You're using Python 2. To do what you expect in Python 2: person = raw_input( "Enter your name: " )

OpenStudy (anonymous):

and also... to print the result that you want to see the syntax would be the following: print 'Hello, ', person or the "+" sign instead of a comma...

OpenStudy (rsmith6559):

The + sign will print exactly what you have. The comma will print what you have and put a space in between.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!