xMutiiNy
xMutiiNy

Reputation: 9

Python 3.3.2 Cosine Rule Unknown Angle

What I currently have is

 x = float(input("Side opposite unknown angle: "))
 y = float(input("Second Side: "))
 z = float(input("Third Side: "))

 print ("Angle is: "+str((x**2+y**2-z**2)/2*x*y)*math.acos)

And the error I receive is

print ("Angle is: "+str((x**2+y**2-z**2)/2*x*y)*math.acos)
TypeError: can't multiply sequence by non-int of type 'builtin_function_or_method'

Upvotes: 0

Views: 1446

Answers (2)

starrify
starrify

Reputation: 14771

print ("Angle is: "+str((x**2+y**2-z**2)/2*x*y)*math.acos)

should be

print ("Angle is: "+str(math.acos((y**2+z**2-x**2)/(2*y*z)))

Notice where the parenthesis are.

Problems:

  1. math.acos is a function that should be invoked.
  2. Arguments of str should include the result of math.acos
  3. You're using the wrong variables in the equation.

Upvotes: 1

Dan D.
Dan D.

Reputation: 74675

Replace math.acos with math.acos((x/360.0)*2*math.pi) if x is in degrees or just math.acos(x) if x is in radians. Also move it within the call to str.

Upvotes: 0

Related Questions