2017-10-19 17 views
1

我目前在python3中遇到了一個問題。爲什麼我得到錯誤。 TypeError:不支持的操作數類型爲+:'int'和'str'?

我最近遇到的錯誤: 類型錯誤:不支持的操作數類型(S)爲+:「詮釋」和「海峽」

我不知道這個問題可能是因此任何幫助將是非常讚賞。

預先感謝

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

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

回答

0

「長度」 是包含字符串的列表。 「sum」對數字類型進行操作。你需要將字符串轉換爲浮點數。嘗試在求和之前添加此行,並總結長度_浮點數:

length_float = [長度元素的浮點數(元素)]

相關問題