Why am I getting token errors

Question:

I am not sure why I am getting a token error statement. The error is
SyntaxError: bad token T_OP on line 7

import math

def law_of_cosines(a,b,theta):

    math.sqrt(int((a**2) + (b**2) − (2*(a)*(b)*(math.cos(math.degrees(theta))))))
 
   
res1 = law_of_cosines(3.0, 4.0, 90)
print(res1)  # should output: 5.0
Asked By: Neil Nair

||

Answers:

it’s the minus sign your should be -

import math

def law_of_cosines(a, b, theta):

    return math.sqrt(a**2 + b**2 - (2 * a * b) * math.cos(math.radians(theta)))
 
   
res1 = law_of_cosines(3.0, 4.0, 90)
print(res1)  # should output: 5.0

math.degrees(rad) -> deg

math.radians(deg) -> rad

Answered By: Hanna
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.