python - Python——总是得到“必须是 str 而不是 int”
问题描述
我想循环阅读单词,直到用户键入stop
或<space>
。当循环停止时,我想连接并打印用户先前输入的所有单词(不包括停止或空格)。
while True:
reply = input('Enter text, [type "stop" to quit]: ')
print (reply)
if reply == 'stop':
break
while len(reply) >3:
reply=reply+1
print (reply)
例如:
回复1是“如何”
回复 2 是“长”
回复 3 是“有”
回复 4 是“它”
回复 5 是“曾经”
期望输出: “已经多久了”
解决方案
很难说出您想要什么,但根据您的编辑,您似乎正在尝试执行以下操作:
replys = []
while True:
reply = input('Enter text, [type "stop" to quit]: ')
print(reply)
if reply == 'stop' or reply == ' ':
print(" ".join(replys))
break
replys.append(reply)
推荐阅读
- c++ - “正在初始化”:无法从“T []”转换为“T []”
- data-modeling - 数据仓库的维度模型(递归/分层)
- linux-kernel - 无法从任何来源获取 URL - 在运行 BitBake 时
- c# - .NET Core 中的 TraceSource 未捕获事件
- python - DRF 此字段为必填项
- javascript - 基于范围的正/负的 JS Sum 套件
- excel - 根据多个条件计算唯一单元格值
- python - python中的多重继承使用函数super()
- python - UnicodeEncodeError:“latin-1”编解码器无法在位置 0 编码字符“\u201d”:序数不在范围内(256)
- c# - 获取模型绑定列表框的 SelectedItem 字符串表示