Need help with a 2d array and if using element values

a is a 200x200 array of integers where two “walkers” take random walks. An element gets a 1 if Walker 1 steps there, a 2 for Walker 2, and a 3 if they both step there. The goal is to count the number of intersections. There is a syntax error at (if CurrentVal1==0:). I’m trying to get the value of the element into CurrentVal1 to test, and then set it accordingly - 1, 2, or 3.

“”"# Reset the variable that holds the value of the current position
# i.e. 0,1, 2, or 3 to 0.
# 0 = no one has stepped here
# 1 = walker 1 has stepped here
# 2 = walker 2 has stepped here
# 3 = both walkers have stepped here (intersection)
CurrentVal1=0

# If the new position is within the array
if startPos1[0]>=0 and startPos1[1]>=0 and startPos1[0]<200 and startPos1[1]<200:
#Get the current value of the new step location
    CurrentVal1=a[(startPos1[0],startPos1[1])]
else:
    # else go 1 step back and choose again
    startPos1=startPos1-np.array(step1)

if CurrentVal1==0:
a[startPos1[0],startPos1[1]]=1
elif CurrentVal1=2:
a[startPos1[0],startPos1[1]]=3
XCount+=1
elif CurrentVal1=3:
XCount+=1"""

I don’t think the syntax error is at this line:

if CurrentVal1==0:

I think the syntax error is at this line:

elif CurrentVal1=2:

You need to use == (double equals) for equality tests and = (single equals) for assignment.

Either that, or the code you have shared with us is not the same as the code you are actually trying to run.

Thanks, it actually was the ==. The == after the if was a typo when I pasted the code.

Thanks a ton.

Bryan Hawkins

Hawkins Engineering

bryan@hawkins-engineering.com

hawkins-engineering.com

770-382-0266 office

770-598-1977 cell