簡體   English   中英

為什么我會出錯。 TypeError:+不支持的操作數類型:“ int”和“ str”?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM