亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我總是從這段代碼中收到錯誤

為什么我總是從這段代碼中收到錯誤

冉冉說 2023-12-29 17:12:17
所以我不斷收到此錯誤 print(float(side / (math.sin(math.radians(float( Degree)))))) TypeError: unsupported operand type(s) for /: 'str' and 'float'import math# for anyone looking at this input opp, 10.7, 65, sin, noprint("This only works for right triangles")print("opp = opposite   adj = adjacent")# variablesside1 = input("Input if your trying to find opposite or adjacent: ")side = input("input length of one side: ")degree = input("Input angle cant use the right angle: ")trig_ratio = input("Input either sin cos tan: ")pos_angle = input("is the right angle below the angle: ")# sinif trig_ratio == "sin"\        and pos_angle == "no"\        and side1 == "opp":    print(float(side / (math.sin(math.radians(float(degree))))))
查看完整描述

4 回答

?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

問題是你試圖將字符串除以浮點數。該變量side永遠不會轉換為浮點數,這就是“TypeError: unsupported operand type(s) for /: 'str' and 'float'”所討論的內容。

使用side = float(input("input length of one side: "))print(float(side) / (math.sin(math.radians(float(degree)))))代替


查看完整回答
反對 回復 2023-12-29
?
一只萌萌小番薯

TA貢獻1795條經驗 獲得超7個贊

您輸入的side變量是,在進行任何算術運算之前str將其轉換為。float

side = float(input("input length of one side: "))


查看完整回答
反對 回復 2023-12-29
?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

輸入函數總是返回一個字符串,嘗試在輸入時將 side 轉換為 int 或 float

side = float(input("input length of one side: "))


查看完整回答
反對 回復 2023-12-29
?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

您正在嘗試用字符串值除法,即,您需要先將“side”值轉換為浮點數,然后嘗試除法。

使用下面的代碼:

print(float(side) / (math.sin(math.radians(float(度)))))


查看完整回答
反對 回復 2023-12-29
  • 4 回答
  • 0 關注
  • 249 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號