Ask Your Question

Revision history [back]

sage worksheet indexing issues

I'm trying to use a sage worksheet for a much different problem, but the issue I'm having can be expressed concisely as follows:

Let's say I have some list A. I want to make several lists (call them MDN(j)) where each list has entries '0,' the 4th to jth elements of A, '99'.

In the end, when I ask it to print MDN(j), it just prints '0,' the 4th to max(j)th elements of A, '99.' That is, if I have j in [4,..,9] and ask it to print MDN(6), it will print MDN(9).

Why can't I access indexed MDN's? Is there a better way to do this?

A=[1,2,3,4,5,6,7,8,9,10,11,12,13]
print('A=',A)

M=[0]
print('M=',M)

N=[99]
print('N=',N)

for j in [4,..,9]:
    D=[A[i] for i in [1,2,..,j]]
    print('D=',D)
    MDN(j)=M+D+N
    print('M+D+N=',MDN(j))

#why is this printing MDN(9)?
print(MDN(6))

output: https://i.sstatic.net/tr6S2vsy.png