Python输入法

问题描述 投票:-1回答:1

我试图执行一本书中所述的以下代码,但是该示例显示括号错误和语法错误。代码如下。

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)
python input methods syntax
1个回答
0
投票

您的示例适用于Python 2,它是Python的旧版本。可能您使用的是版本3。Python3的变体为:

print("How old are you?", end=' ')
age = input()
print("How tall are you?", end=' ')
height = input()
print("How much do you weigh?", end=' ')
weight = input()
print("So, you're %r old, %r tall and %r heavy." % (age, height, weight))
© www.soinside.com 2019 - 2024. All rights reserved.