如何使用Python接收输入并打印?

How to receive input and print it using Python?

我写了以下代码:

1
2
name = input("What is your name:")
print(name)

当我输入我的名字时,它给出了下面的错误

/usr/bin/python2.7 /home/sreedhar/PycharmProjects/Sample1/sample.py
What is your name: Sree Traceback (most recent call last): File
"/home/sreedhar/PycharmProjects/Sample1/sample.py", line 1, in

name = input("What is your name:") File"", line 1, in NameError: name 'Sree' is not defined

Process finished with exit code 1

有人能帮我调试一下这段代码吗,我今天已经启动了python。我在linux mint上使用了python community 17.2。


raw_input代替:

1
2
name = raw_input("What is your name:")
print(name)

请参见python 2.7获取用户输入并以字符串形式操作(不带引号)

input在python 3.x上工作,而不是在2.x中工作