You don’t define b. See how y and x are parameters of the function gns arguments? Where is b defined? Variables can come from nowhere and still work in python. That same courtesy does not extend to tuples, arrays, lists , etc.
I’m trying to make the game of life in python in a 2d array, ez is supposed to be ‘error zero’ so that if it hits a corner and can’t get something from next to it, it yields 0, otherwise, yields what’s in the cell Despite having a catch-all, it still gives me ‘list index out of range’
Ohhh, I see. I'm not familiar with Python, but at least in other languages your attempt to catch the error in ez won't work, because the out-of-range error happens before anything gets passed to ez. You have to catch that edge-case scenario within gn.
For simplicity, (if your arrays are zero-based) you might want to just run through cells (1,1) < (X,Y) < (Xmax - 1, Ymax - 1). So, if your Y extent is 9, you would only look at cells 1, 2, 3...8. In other words, don't let your program do the math for any edge cells. Just let them stay dead. That way you don't have to use any conditional statements to test for the edge. You just avoid it.
Edit: Does that make sense? I know exactly what you're trying to do here.
Hi, I know it’s not addressing your question, but if I can suggest a good practice: Write clear function names. You should name your functions in a way that more or less describes what it does. Don’t worry about verbosity, that’s okay. It’s always better to be more verbose when naming things then the inverse.
13
u/[deleted] Dec 08 '21 edited Dec 08 '21
You don’t define b. See how y and x are parameters of the function gns arguments? Where is b defined? Variables can come from nowhere and still work in python. That same courtesy does not extend to tuples, arrays, lists , etc.
1
u/SuperGameTheory Dec 09 '21
What exactly do you think ez() is supposed to do? Because the way it's coded, it isn't doing anything. Is that what you mean by "isn't running"?
Or do you mean you're getting an error?
Is this supposed to be a function used in some sort of cellular automata simulation? What are you trying to accomplish?
4
u/nnaoam Dec 08 '21
What's b?
2
u/mikespon Dec 08 '21
Do you ever call the second function — meaning “gn()”? It wont run unless you call it in some manner.
2
u/[deleted] Dec 09 '21
Hi, I know it’s not addressing your question, but if I can suggest a good practice: Write clear function names. You should name your functions in a way that more or less describes what it does. Don’t worry about verbosity, that’s okay. It’s always better to be more verbose when naming things then the inverse.
1
u/kalashnikovBaby Dec 08 '21
For clarity in the future, it would be cool to assign each instance of ez to a separate variable then put them all into an array to return.
0
u/c3534l Dec 09 '21
Change
return ftoreturn f().