【发布时间】:2017-12-20 23:18:34
【问题描述】:
import math
def SOH(oppositeSOH, hypotenuseSOH):
oppDIVhyp = oppositeSOH / hypotenuseSOH
soh = math.asin(oppDIVhyp)
print("The angle theta is equivelent to", soh)
def CAH(adjacentCAH, hypotenuseCAH):
adjDIVhyp = adjacentCAH / hypotenuseCAH
cah = math.acos(adjDIVhyp)
print("Angle theta is equivelent to", cah)
def TOA(oppositeTOA, adjacentTOA):
oppDIVhyp = oppositeTOA / adjacentTOA
toa = math.atan(oppDIVadj)
print("Angle theta is equivelent to", toa)
SOHCAHTOA = input("Do you want to calculate angle theta with a: soh, b: cah, c: toh ")
A = SOHCAHTOA.upper()
if A == 'A':
oppositeSOH = int(input("Enter the length of the opposite side "))
hypotenuseSOH = int(input("Enter the length of the hypotenuse "))
SOH(oppositeSOH, hypotenuseSOH)
if A == 'B':
adjacentCAH = int(input("Enter the length of the adjacent side "))
hypotenuseCAH = int(input("Enter the length of the hypotenuse "))
CAH(adjacentSOH, hypotenuseSOH)
if A == 'C':
oppositeCAH = int(input("Enter the length of the opposite side "))
adjacentCAH = int(input("Enter the length of the hypotenuse "))
TOA(oppositeSOH, adjacentSOH)
当我将“oppDIVhyp”、“adjDIVhyp”或“oppDIVhyp”放入 math.a[sin、cos 或 tan] 时,我得到一个数学域错误:
Traceback (most recent call last):
File "C:\Users\Alex\Documents\sohcahtoa.py", line 23, in <module>
SOH(oppositeSOH, hypotenuseSOH)
File "C:\Users\Alex\Documents\sohcahtoa.py", line 5, in SOH
soh = math.asin(oppDIVhyp)
ValueError: math domain error
数学域错误是什么意思?
【问题讨论】:
-
当您遇到这些错误时,您/用户输入了哪些值?可能只是您输入的值无法计算。比炒作或类似的东西更长的形容词。
-
可能是因为您使用的变量尚未赋值。 (假设您选择“B”。您设置了 *CAH,然后使用 *SOH。)
-
刚刚意识到并编辑了这一点
-
因为
oppDIVhyp可能不在[-1,1]... -
感谢 mypetlion 是 m8 的问题
标签: python math trigonometry