的raw_input()的Python(了解Python中的困难的方法练习题11)

问题描述:

我做了提问,从“学习Python的辛苦”的第三版行使泽德·肖在我的代码如下所示:的raw_input()的Python(了解Python中的困难的方法练习题11)

print "How old are you?", 

age = raw_input() 

print "How tall are you?", 

height = raw_input() 

print "How much do you weigh?", 

weight = raw_input() 

print "So, you're %r old, %r tall and %r heavy." % (age, height, weight) 

和输出应该是这样的:

How old are you? 38 

How tall are you? 6'2" 

How much do you weigh? 180lbs 

So, you're '38' old, '6\'2"' tall and '180lbs' heavy. 

但是,因为我使用Python 3,输出最初的样子:

How old are you? 
Traceback (most recent call last): 
    File "script.py", line 2, in <module> 
    age = raw_input() 
NameError: name 'raw_input' is not defined 

再像曾经我更换的raw_input()与输入():

How old are you? 
Traceback (most recent call last): 
    File "script.py", line 2, in <module> 
    age = input() 
EOFError: EOF when reading a line 
+2

看起来像的Python 2代码一个Python 3的系统上。另一方面,'print'你多大了?','似乎能够工作,那就是Python 2的语法。这里有点可疑。 – Matthias

+0

打印应该是print()。这是Py2和Py3的另一个区别 – Mangohero1

+0

也许与此有关? https://*.com/q/17675925/10077 –

对于Python 3尝试用简单地更换所有 “的raw_input()” 的 “输入()” 已取代 “的raw_input()”