切线问题
Tangent Problems
好吧,我说的切线不是逆切线,而是可以解决直角三角形缺角长度的切线。到目前为止,我已经能够将另一条腿除以相邻的长度。
#this is for a 6,8, 10 triangle!
#y is 8, x is 6
#if you look on the table, 1.3333 is near 53 degrees
if(a==b):
print("This is a right triagle b/c the legs are equal to the hypotnuse!")
tan = input("Would you like to find the tangent of angle A? : ")
if(tan=="Yes"):
print("Lets do this!")
#works with 6,8,10 triangle for now!
print(y,"/",x)
tan = (str(float(y)/float(x)))
round(float(tan),3)
print(round(float(tan),3))
print("Looking for rounded tan in table!")
#remember that 1.333 is near 53 degrees (see on trig table)
if(tan == 1.333):
print("<A == ", 53)
print("<B == 90")
c = str(int(53)+int(90))
c2 = str(int(180)-int(c))
print("<C == ",c2)
else:
print("Nope")
elif(tan=="No"):
print("See you!")
exit(0);
由于某些原因,程序只会使用else 语句,说不。请帮忙!非常感谢。
您在 舍入 后没有更新 tan
。请注意,float 对象是 immutable 和 round
returns 数字类型;舍入后 tan
没有就地更新。
您需要一个赋值来将返回的浮动对象重新绑定到 tan
:
tan = round(float(tan), 3)
这里有多个问题:
tan
是一个字符串,所以它永远不会等于浮点数。请注意,您只分配给 tan 一次。舍入操作的输出被打印或丢弃,但不存储在 tan
中。你可能想要这样的东西:
tan = round(float(y) / float(x), 3)
您将浮点数与 ==
进行比较。你应该永远不要检查与浮点数的相等性! (除非您将它们分配为文字。)您应该始终检查两个数字的接近程度:
if abs(tan - 1.333) < 1e5:
此外:不要将任何内容转换为字符串,除非您需要对字符串进行操作(例如,对其进行索引)。你为什么不用Pythonmath函数?
好吧,我说的切线不是逆切线,而是可以解决直角三角形缺角长度的切线。到目前为止,我已经能够将另一条腿除以相邻的长度。
#this is for a 6,8, 10 triangle!
#y is 8, x is 6
#if you look on the table, 1.3333 is near 53 degrees
if(a==b):
print("This is a right triagle b/c the legs are equal to the hypotnuse!")
tan = input("Would you like to find the tangent of angle A? : ")
if(tan=="Yes"):
print("Lets do this!")
#works with 6,8,10 triangle for now!
print(y,"/",x)
tan = (str(float(y)/float(x)))
round(float(tan),3)
print(round(float(tan),3))
print("Looking for rounded tan in table!")
#remember that 1.333 is near 53 degrees (see on trig table)
if(tan == 1.333):
print("<A == ", 53)
print("<B == 90")
c = str(int(53)+int(90))
c2 = str(int(180)-int(c))
print("<C == ",c2)
else:
print("Nope")
elif(tan=="No"):
print("See you!")
exit(0);
由于某些原因,程序只会使用else 语句,说不。请帮忙!非常感谢。
您在 舍入 后没有更新 tan
。请注意,float 对象是 immutable 和 round
returns 数字类型;舍入后 tan
没有就地更新。
您需要一个赋值来将返回的浮动对象重新绑定到 tan
:
tan = round(float(tan), 3)
这里有多个问题:
tan
是一个字符串,所以它永远不会等于浮点数。请注意,您只分配给 tan 一次。舍入操作的输出被打印或丢弃,但不存储在tan
中。你可能想要这样的东西:tan = round(float(y) / float(x), 3)
您将浮点数与
==
进行比较。你应该永远不要检查与浮点数的相等性! (除非您将它们分配为文字。)您应该始终检查两个数字的接近程度:if abs(tan - 1.333) < 1e5:
此外:不要将任何内容转换为字符串,除非您需要对字符串进行操作(例如,对其进行索引)。你为什么不用Pythonmath函数?