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
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
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
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