python - 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)
解决方案
您的示例适用于 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))
推荐阅读
- sql-server - 如何在 SQL 中手动输入列名而不使用数据透视表
- python - 如果用户输入0,则填写一个继续从用户那里读取整数的缺失语句
- r - 如何在 R 中使用 plotly 绘制 3d 曲面图?
- r - case_when 与 numeric(0) 的行为
- java - Spark二进制列拆分为多列
- android - Android 分页和分组模型
- x509certificate - ASN.1的基本理解
- python - ValueError:信号仅在主线程中有效(Python / Scrapy + Flask)
- javascript - 如何在本机反应中始终将项目呈现在顶部
- pandas - 熊猫数据框。为什么显示的数据与存储的数据不同?