Nevermind I found it I never closed the sedonf parenthesis when defining the value of c c = math.sqrt(a2 + b2  2ab * math.cos(gamma_rad))
Syntaxerror when the syntax is right?
Rachid, Chadi
0
Reputation points
Here is the snippet of code I have a problem with: When I try to run it, a Syntaxerror message appears on line 6, it highlights in red the 'r' in 'return' and says invalid syntax. No matter how hard I look at any textbook or documentation, I think my formatting is correct here. What am I missing?
import math
def loc_calc(a ,b ,gamma_deg):
gamma_rad = gamma_deg * math.pi / 180
c = math.sqrt(a**2 + b**2  2*a*b * math.cos(gamma_rad)
return c
2 answers
Sort by: Most helpful


Vahid Ghafarpour 14,455 Reputation points
20240130T15:24:58.1366667+00:00 Thanks for posting your question in the Microsoft Q&A forum. You need to close the parenthesis of sqrt at the end of line 5.
c = math.sqrt(a2 + b2  2ab * math.cos(gamma_rad))
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **