![](/img/trans.png)
[英]why am I getting the TypeError: unsupported operand type(s) for -: 'str' and 'int'
[英]Why am I getting error. TypeError: unsupported operand type(s) for +: 'int' and 'str'?
我目前在python3中遇到问题。
我最近遇到了错误:TypeError:+不支持的操作数类型:“ int”和“ str”
我不知道可能是什么问题,因此不胜感激。
lengths = input("Enter the Lengths of the Sides of the Shape Seperated by commas: ").split(',')
answer = sum(lengths)
print("+".join(lengths) + "= %s" % (answer))
“长度”是一个包含字符串的列表。 “ sum”对数字类型进行运算。 您需要将字符串转换为浮点数。 尝试在总和之前添加此行,并在lengths_float上总和:
lengths_float=[float(element) for element in lengths]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.