[英]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对象是不可变的,并且round
返回数字类型。 四舍五入后没有tan
的就地更新。
您需要分配将返回的float对象重新绑定到tan
:
tan = round(float(tan), 3)
这里有多个问题:
tan
是一个字符串,因此永远不会等于浮点数。 请注意,您只分配一次tan。 舍入运算的输出将被打印或丢弃,但不会存储在tan
。 您可能想要这样的东西:
tan = round(float(y) / float(x), 3)
您可以使用==
与浮点数进行比较。 您永远不要检查浮点数是否相等! (除非您将它们分配为文字。)您应该始终检查两个数字的接近程度:
if abs(tan - 1.333) < 1e5:
另外:不要将任何东西都转换为字符串,除非您需要对字符串进行操作(例如,对其进行索引)。 为什么不使用Python 数学函数?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.