[英]Tangent Problems
Okay, the tangent I'm talking about isn't tangent inverse, but the tangent that is able to solve missing angle lengths in a right triangle. 好的,我在说的切线不是切线逆,而是能够解决直角三角形中缺少的角度长度的切线。 So far, I've been able to divide the opposite leg by a adjacent length. 到目前为止,我已经能够将另一条腿除以相邻的长度。
#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);
For some reason, the program will only use the else statement, and say nope. 由于某种原因,该程序将仅使用else语句,并说不。 Please help! 请帮忙! THANKS so much in advance. 非常感谢。
You're not updating tan
after rounding . 四舍五入后,您无需更新tan
。 Note that float objects are immutable and round
returns a numeric type; 请注意,float对象是不可变的,并且round
返回数字类型。 there isn't an in-place update of tan
after rounding. 四舍五入后没有tan
的就地更新。
You need an assignment to rebind the returned float object to tan
: 您需要分配将返回的float对象重新绑定到tan
:
tan = round(float(tan), 3)
There are multiple problems here: 这里有多个问题:
tan
is a string, so it will never equal a floating point number. tan
是一个字符串,因此永远不会等于浮点数。 Note that you only assign to tan once. 请注意,您只分配一次tan。 The output of your rounding operations is either printed or discarded but not stored in tan
. 舍入运算的输出将被打印或丢弃,但不会存储在tan
。 You probably want something like this: 您可能想要这样的东西:
tan = round(float(y) / float(x), 3)
You compare against a floating point number with ==
. 您可以使用==
与浮点数进行比较。 You should never check equality with floating point numbers! 您永远不要检查浮点数是否相等! (unless you assign them as literals.) You should instead always check how close two numbers are: (除非您将它们分配为文字。)您应该始终检查两个数字的接近程度:
if abs(tan - 1.333) < 1e5:
Also: Don't convert anything to strings, unless you need to operate on the string (eg, index it). 另外:不要将任何东西都转换为字符串,除非您需要对字符串进行操作(例如,对其进行索引)。 Why don't you use Python math functions? 为什么不使用Python 数学函数?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.