所以我不断收到此错误 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条经验 获得超5个赞
问题是你试图将字符串除以浮点数。该变量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)))))
代替
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
您输入的side
变量是,在进行任何算术运算之前str
将其转换为。float
side = float(input("input length of one side: "))
跃然一笑
TA贡献1826条经验 获得超6个赞
输入函数总是返回一个字符串,尝试在输入时将 side 转换为 int 或 float
side = float(input("input length of one side: "))
开心每一天1111
TA贡献1836条经验 获得超13个赞
您正在尝试用字符串值除法,即,您需要先将“side”值转换为浮点数,然后尝试除法。
使用下面的代码:
print(float(side) / (math.sin(math.radians(float(度)))))
添加回答
举报
0/150
提交
取消