4 回答

TA貢獻1993條經(jīng)驗 獲得超6個贊
問題是你試圖將字符串除以浮點數(shù)。該變量side
永遠不會轉(zhuǎn)換為浮點數(shù),這就是“TypeError: unsupported operand type(s) for /: 'str' and 'float'”所討論的內(nèi)容。
使用side = float(input("input length of one side: "))
或print(float(side) / (math.sin(math.radians(float(degree)))))
代替

TA貢獻1795條經(jīng)驗 獲得超7個贊
您輸入的side
變量是,在進行任何算術(shù)運算之前str
將其轉(zhuǎn)換為。float
side = float(input("input length of one side: "))

TA貢獻1826條經(jīng)驗 獲得超6個贊
輸入函數(shù)總是返回一個字符串,嘗試在輸入時將 side 轉(zhuǎn)換為 int 或 float
side = float(input("input length of one side: "))

TA貢獻1836條經(jīng)驗 獲得超13個贊
您正在嘗試用字符串值除法,即,您需要先將“side”值轉(zhuǎn)換為浮點數(shù),然后嘗試除法。
使用下面的代碼:
print(float(side) / (math.sin(math.radians(float(度)))))
添加回答
舉報