【发布时间】:2017-06-23 22:49:27
【问题描述】:
我正在用 python 创建一个大型计算器,但我遇到了一个问题。我正在尝试使用余弦定律来找到 SSS 三角形中的角度,但我看不到哪里出错了。
elif qchoice5 == 4:
while True:
try:
print("======================================================================")
a = float(input("what is side a?"))
break
except ValueError:
print("======================================================================")
print("please enter a valid option")
while True:
try:
print("======================================================================")
b = float(input("what is side b?"))
break
except ValueError:
print("======================================================================")
print("Please enter a valid option")
while True:
try:
print("======================================================================")
c = float(input("what is side c?"))
break
except ValueError:
print("======================================================================")
print("Please enter a valid option")
print(((b**2)+(c**2)-(a**2))/(2*a*b))
ans = math.acos((((b**2)+(c**2)-(a**2))/(2*a*b)))
print(ans)
每次运行都会报错
ans = math.degrees(math.acos((((b*b)+(c*c)-(a*a))/(2*a*b))))
ValueError: math domain error
谁能给我任何关于如何让它工作的指示?
【问题讨论】:
-
您在全等三角形的背景下谈论 SSS。在这种情况下,您应该检查以确保该三角形所有边的 x + y > z。
-
欢迎来到 StackOverflow。请阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您描述的问题。
-
特别是,给我们一组引起问题的分配的a,b,c值。
-
math.acos((((b**2)+(c**2)-(a**2))/(2*a*b)))- 看看这个表达式。现在看看余弦定律。现在回到你的表情。你看到差异了吗?重做你的代数。 -
@Prune 我发现为了不返回错误 A 必须 = 最大,B = 最小,c 必须 = 中间数。即使它给出了错误的答案。
标签: python trigonometry