Ask Your Question

Revision history [back]

click to hide/show revision 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

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

a few basic facts about Python lists and Sage's symbolic functions :

  • Lists are indexed by square brackets ([), not parentheses ( ().
  • Their indices start at 0, not 1.
  • Python does not accept indexing lists by list in general ; however, Python has slice indexing 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).
  • In Sage (not Python in general), the notation 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,