2017-12-20 13 views
-1
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) 

Als ich put 'oppDIVhyp', 'adjDIVhyp' oder 'oppDIVhyp' in math.a [sin, cos oder tan], es ist ein Fehler Mathe Domäne I im Gegenzug:Warum erhalte ich bei Verwendung von asin, acos und atan einen mathematischen Domänenfehler?

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 

Was bedeutet der mathematische Domänenfehler?

+1

Welche Werte geben Sie/der Benutzer ein, wenn Sie diese Fehler erhalten? Es kann nur sein, dass Sie Werte eingeben, die nicht berechnet werden können. Ein Adj, der länger ist als ein Hyp oder so etwas. – mypetlion

+0

Wahrscheinlich, weil Sie Variablen verwenden, denen Sie keine Werte zugewiesen haben. (Nehmen wir an, Sie wählen "B". Sie setzen \ * CAH, aber dann * verwenden * \ * SOH.) – cHao

+0

Wurde nur realisiert und bearbeitet –

Antwort

2

Die ValueError: math domain error wird erzeugt, wenn eine Funktion aufgefordert wird, einen Wert mit Parametern zu berechnen, die für die Berechnung nicht sinnvoll sind. Wenn Sie beispielsweise nach dem Protokoll einer negativen Nummer fragen. In diesem Fall wette ich, dass der Benutzer Werte eingibt, die für ein rechtwinkliges Dreieck unmöglich sind. Eine Hypotenuse, die zum Beispiel kürzer ist als eine der beiden anderen Seiten.

Verwandte Themen