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
Solved! Go to Solution.
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
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
You are my hero, thank you so much!
Don't forget to make the same change in the last elif