0
我做了提問,從「學習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
看起來像的Python 2代碼一個Python 3的系統上。另一方面,'print'你多大了?','似乎能夠工作,那就是Python 2的語法。這裏有點可疑。 – Matthias
打印應該是print()。這是Py2和Py3的另一個區別 – Mangohero1
也許與此有關? https://stackoverflow.com/q/17675925/10077 –