Syntaxerror when the syntax is right?

Rachid, Chadi 0 Reputation points
2024-01-30T15:17:33.3533333+00:00

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
Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop skilled behavior.
627 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rachid, Chadi 0 Reputation points
    2024-01-30T15:23:53.91+00:00

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


  2. Vahid Ghafarpour 14,455 Reputation points
    2024-01-30T15: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 **

    0 comments No comments