0

This is a basic simple Python question.. I want to take the name as an input from user and print it on screen. I am using PyCharm Community Edition 2017.2.3 IDE. My code is as follows:

name=input("Enter your name ")
print(name)

I am getting the below error. Should be a very simple fix.. but not getting it... Any suggestions.... I am new to Python.....

C:\Python27\python.exe C:/Users/sourav/PycharmProjects/python_project/dummy1.py
Enter your name Sourav
Traceback (most recent call last):
  File "C:/Users/sourav/PycharmProjects/python_project/dummy1.py", line 1, in <module>
    name=input("Enter your name ")
  File "<string>", line 1, in <module>
NameError: name 'Sourav' is not defined

Process finished with exit code 1

bhansa
  • 7,282
  • 3
  • 30
  • 55
Sourav Gupta
  • 227
  • 5
  • 17
  • use `raw_input()` or convert your input to string and display. – bhansa Nov 11 '17 at 17:16
  • Thanks Bhansa and UrbanConor... It is actually an issue with the version.... In Python Version 2, raw_input() is considered as a string while input() runs the input as an expression. I wouldn't have faced the issue in version 3. I was using version 2. – Sourav Gupta Nov 11 '17 at 17:45

1 Answers1

1

Either use raw_input() here.

name = raw_input("Enter your name ")
print(name)

Or give input as "Sourav" with the quotes using input

bhansa
  • 7,282
  • 3
  • 30
  • 55