3 ms·
I also thought that was odd, and used the latter version in the first few exercises. But later there was some code of the form: def move(p, U): q = []
by nswanberg 15y ago
I also thought that was odd, and used the latter version in the first few exercises. But later there was some code of the form:
def move(p, U):
q = []
for i in range(len(p)):
s = pExact * p[(i-U) % len(p)]
s = s + pOvershoot * p[(i-U-1) % len(p)]
s = s + pUndershoot * p[(i-U+1) % len(p)]
q.append(s)
return q
where the index is used to access the previous and next elements in a list.
There's a more idiomatic way to get this index variable(http://stackoverflow.com/questions/522563/accessing-the-index-in-python-for-loops http://stackoverflow.com/questions/522563/accessing-the-inde...), but using a consistent, easy to understand iteration method allows the poor confused student (i.e. me) to spend more time focusing on the concept being taught.
So the code could be intentional, or could be an accident. But I expect that sooner rather than later there will be some data to show which method, if any, is better for the students, and the classes will be adjusted accordingly.
By the way, did anyone else find these exercises addictive? I can begin to appreciate why the Farmville cow-clickers keep at it.