| 1 | initial version |
In your loop, the line :
MDN(j)=M+D+N
doesn't do what you seem to think it does.
It (re-)defines a symbolic function (a. k. a. "callable symbolic expression") with one argument j and returning the current value of M+D+N (and ignores its argument j).
Your call
print(MDN(6))
is executed immediately after the last execution of your loop body, where D is [A[i] for i in (1,2,..,9]. Therefore, any call to the MDN function will return this value.
You seem to want to create a MDM list of lists, with at least 10 elements, and update its 5th to 10th elements to the values you generate. In order to do this, you must remember
| 2 | No.2 Revision |
In your loop, the line :
MDN(j)=M+D+N
doesn't do what you seem to think it does.
It (re-)defines a symbolic function (a. k. a. "callable symbolic expression") with one argument j and returning the current value of M+D+N (and ignores its argument j).
Your call
print(MDN(6))
is executed immediately after the last execution of your loop body, where D is [A[i] for i in (1,2,..,9]. Therefore, any call to the MDN function will return this value.
You seem to want to create a MDM list of lists, with at least 10 elements, and update its 5th to 10th elements to the values you generate. In order to do this, you must remember
[), not parentheses ( ().L[a:b] where a and b are integers (or variables with integer values), denoting the sublist of L sarting with its ath element and up to its b-1th element (in other word, a is the first included element and b is the first *excluded` element).f(x, y...)=... (re-)defines a symbolic function (a. k. a. "callable symbolic expression") f with arguments x, y, etc... ; f(u, v) is the value of this symbolic expression applied to the arguments x=u and y=v.There are a lot of good Python tutorials to choose from ; Sage has an excellent (if slightly outdated) tutorial book, also available as a printed book.
HTH,
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.