Select to view content in your preferred language

Invalid Syntax Error Assistance

191
3
Jump to solution
2 weeks ago
RemyCrettol
New Contributor

Hey all, I am trying to use ArcGIS and Python code to prioritize and map river corridor protections for flood resilience. I am struggling with this line of code that is giving me a SyntaxError: invalid syntax. I think it is trying to read 'Mulitple' as part of the code and not as a word/value.  See line 4 error below as well as full code under that. Really been struggling to resolve this so any assistance would be much appreciated. 

File "<string>", line 4
if (Upstream_MassFailures == 'multiple' and upstream_constrained = 1):
                                                                       ^
SyntaxError: invalid syntax
.

 __________________________________________________________________________________________________

def calculate_sediment_loaded(confinement_type, ChannelEvolutionStage, GeomorphicStreamCondition, GeoAssessSensitivity, Upstream_MassFailures, constrained, upstream_constrained😞

   

    #  Check if the reach is downstream of a constrained reach with mass failures and conditions are met

    if (Upstream_MassFailures == 'Multiple' and upstream_constrained = 1):

        # Count how many primary criteria are met

        criteria_met = sum([

            confinement_type in ('BD', 'VB'),

            ChannelEvolutionStage in ('III', 'IV'),

            GeoAssessSensitivity in ('Very High', 'Extreme'),

            GeomorphicStreamCondition in ('Fair', 'Poor')

        ])        

        

        # If at least 3 out of 4 conditions are met, return 1

        if criteria_met >= 3:

            return 1

 

elif (upstream_percent_straightened > 40 and straightening_percent is not None and straightening_percent <= 40):

            return 1

 

elif (Constrained is not None and constrained = 0 and upstream_constrained = 1):

            return 1

 

 return 0  # Default case if conditions aren't met

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

if (Upstream_MassFailures == 'multiple') and (upstream_constrained == 1):

you forgot the last = hence it errored.   I put in a couple of extra enclosing ( )'s for good measure


... sort of retired...

View solution in original post

3 Replies
DanPatterson
MVP Esteemed Contributor

if (Upstream_MassFailures == 'multiple') and (upstream_constrained == 1):

you forgot the last = hence it errored.   I put in a couple of extra enclosing ( )'s for good measure


... sort of retired...
RemyCrettol
New Contributor

You are my hero, thank you so much!

0 Kudos
KenBuja
MVP Esteemed Contributor

Don't forget to make the same change in the last elif

0 Kudos