When executing the code below, a "Syntax: invalid syntax" Syntax error appears. I cannot identify the error

Asked

Viewed 75 times

-3

from math import pi, sin, cos

from math import sqrt, acos, log, exp
 

def d_rsc (Z, p, Td, Rsea, Rstab):
    
    m =  35 * sqrt ((1224 * ((cos (Z))**2) + 1)
    TRTg = 1.021 - 0.084 * sqrt(m*((949*p*10**(-5)) + 0.051))
    u = exp(0.1133 - (log(2.61+1)) + 0.0393 * (Td * 9/5+32)
    Tw = 1 - 0.0077*(u*m)**0.3
    Ta =  0.935**m
    Rsc = Rsea * TRTg* Tw * Ta
    Rs = Rstab/3.6
    return TRTg, Tw, Ta, Rsc, Rs

Td = 17.25
Z = 1.570796
p = 8.805
Rsea = 487.2009
Rstab = -81.806

TRTg, Tw, Ta, Rsc, Rs = d_rsc (Z, p, Td, Rsea, Rstab)
c = 1 - Rs/Rsc

print (Tw, Ta. Rsc, Rs)
print (c)

****File "<ipython-input-18-a11db0f9d756>", line 12
    TRTg = 1.021 - 0.084 * sqrt(m*((949*p*10**(-5)) + 0.051))
    ^
SyntaxError: invalid syntax****

1 answer

1


You forgot to close the parentheses on lines 8 and 10, and put a dot in place of the comma on line 26.

With the changes made, your code would look like this:

from math import pi, sin, cos

from math import sqrt, acos, log, exp
 

def d_rsc (Z, p, Td, Rsea, Rstab):
    
    m =  35 * sqrt ((1224 * ((cos (Z))**2) + 1))
    TRTg = 0.084 * sqrt(m*((949*p*10**(-5)) + 0.051))
    u = exp(0.1133 - (log(2.61+1)) + 0.0393 * (Td * 9/5+32))
    Tw = 1 - 0.0077*(u*m)**0.3
    Ta =  0.935**m
    Rsc = Rsea * TRTg* Tw * Ta
    Rs = Rstab/3.6
    return TRTg, Tw, Ta, Rsc, Rs

Td = 17.25
Z = 1.570796
p = 8.805
Rsea = 487.2009
Rstab = -81.806

TRTg, Tw, Ta, Rsc, Rs = d_rsc (Z, p, Td, Rsea, Rstab)
c = 1 - Rs/Rsc

print (Tw, Ta, Rsc, Rs)
print (c)
  • Thank you Lucas! Solved my problem.

  • Don’t forget to mark as resolved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.