简体   繁体   English

为什么我会出错。 TypeError:+不支持的操作数类型:“ int”和“ str”?

[英]Why am I getting error. TypeError: unsupported operand type(s) for +: 'int' and 'str'?

I am currently having trouble with a program in python3. 我目前在python3中遇到问题。

I have recently come across the error: TypeError: unsupported operand type(s) for +: 'int' and 'str' 我最近遇到了错误:TypeError:+不支持的操作数类型:“ int”和“ str”

I have no idea what the problem could be so any help would be much appreciated. 我不知道可能是什么问题,因此不胜感激。

lengths = input("Enter the Lengths of the Sides of the Shape Seperated by commas: ").split(',')
            answer = sum(lengths)

            print("+".join(lengths) + "= %s" % (answer))

"lengths" is a list containing strings. “长度”是一个包含字符串的列表。 "sum" operates on numeric types. “ sum”对数字类型进行运算。 You need to convert strings to floats. 您需要将字符串转换为浮点数。 Try to add this line before sum, and sum on lengths_float: 尝试在总和之前添加此行,并在lengths_float上总和:

lengths_float=[float(element) for element in lengths]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我收到 TypeError: unsupported operand type(s) for -: 'str' and 'int' - why am I getting the TypeError: unsupported operand type(s) for -: 'str' and 'int' 为什么我收到 TypeError: unsupported operand type(s) for /: 'str' and 'int'? - Why am I getting TypeError: unsupported operand type(s) for /: 'str' and 'int'? python TypeError“+不支持的操作数类型:'int'和'str'”为什么我会得到这个? - python TypeError "unsupported operand type(s) for +: 'int' and 'str'" Why am I getting this? 我收到 typeError: unsupported operand type(s) for -: 'str' and 'int' - I'm getting a typeError: unsupported operand type(s) for -: 'str' and 'int' 为什么我会收到以下错误消息:不支持的操作数类型 +:'int' 和 'str'。 请参阅下面的 python 规则主体 - Why am I getting the following error message: Unsupported operand type(s) for +: ‘int’ and ‘str’. See below the python rules body 为什么我得到不支持的操作数类型 -: 'str' 和 'str' 错误 - Why am I getting unsupported operand type(s) for -: 'str' and 'str' error 我收到此错误,不支持 ** 或 pow() 的操作数类型:'str' and 'int' - I am getting this error unsupported operand type(s) for ** or pow(): 'str' and 'int' 为什么我收到TypeError:+不支持的操作数类型 - Why am I getting TypeError: unsupported operand type(s) for + 为什么我得到:TypeError: unsupported operand type(s) for -: 'str' and 'str' 即使 dtypes 显示所有 float64 - Why am I getting: TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’ even though dtypes is showing all float64 不断收到类型错误:+ 的不支持的操作数类型:python 中的“int”和“str” - keep getting typeerror: unsupported operand type(s) for +: 'int' and 'str' in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM