首页 > 解决方案 > Python输入法

问题描述

我尝试按照书中所述执行以下代码,但 ide 显示括号错误和语法错误。代码如下。

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)

标签: pythoninputmethodssyntax

解决方案


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

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))

推荐阅读