I've got some nested functions and I'm trying to sum the total number of times that something occurs using:
if C[city_cell_x][city_cell_y] == 1:
cityCount +=1
but as this is within a function:
# Animate
fig = plt.figure()
plt.axis("on")
ims = []
for t in range(totalTime):
print(str(r), " Time = " + str(t))
ims.append((plt.imshow(C, cmap="Accent"),))
C = mapRun(C)
if C[city_cell_x][city_cell_y] == 1:
cityCount +=1
im_ani = animation.ArtistAnimation(
fig, ims, interval=interval, repeat_delay=3000, blit=True
)
# Save the animation?
if save:
print("Saving...")
im_ani.save(("Repeat" + str(r) + ".html"), writer="html", fps=60, dpi=75)
which I am then looping over, it is either not successfully counting and just returning zero at the end, of it is raising "cityCount referenced before assignment" even though it is referenced at the start of the code (outside of the function)
I can provide the entire code if that is easier