简体   繁体   中英

Python - Printing user input on screen

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

Either use raw_input() here.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM