Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Noob question about lists in sum()

Hi there, I have a (presumably) very easy question:

var('k') sum(1/k, k, 1, 5)

works, but

dings = [1 , 2, 3, 4, 5] length = len(dings) sum(1/dings[k], k, 0, length - 1)

does not.

Error Message:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_6.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZGluZ3MgPSBbMSAsIDIsIDMsIDQsIDVdCmxlbmd0aCA9IGxlbihkaW5ncykKc3VtKDEvZGluZ3Nba10sIGssIDAsIGxlbmd0aCAtMSAp"),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/tmp/tmpDDv20Z/___code___.py", line 5, in <module> exec compile(u'sum(_sage_const_1 /dings[k], k, _sage_const_0 , length -_sage_const_1 ) File "", line 1, in <module>

File "expression.pyx", line 4163, in sage.symbolic.expression.Expression.__index__ (sage/symbolic/expression.cpp:20198) File "expression.pyx", line 745, in sage.symbolic.expression.Expression._integer_ (sage/symbolic/expression.cpp:5152) TypeError: unable to convert x (=k) to an integer

So I tried writing it with dings[int(k)], didn't work either.

Why? Thanks!

Noob question about lists in sum()

Hi there, I have a (presumably) very easy question:

var('k')
sum(1/k, k, 1, 5)

5)

works, but

dings = [1 , 2, 3, 4, 5]
length = len(dings)
sum(1/dings[k], k, 0, length - 1)

1)

does not.

Error Message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_6.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -- -*- coding: utf-8 --\n" -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZGluZ3MgPSBbMSAsIDIsIDMsIDQsIDVdCmxlbmd0aCA9IGxlbihkaW5ncykKc3VtKDEvZGluZ3Nba10sIGssIDAsIGxlbmd0aCAtMSAp"),globals())+"\n"); _support_.preparse_worksheet_cell(base64.b64decode("ZGluZ3MgPSBbMSAsIDIsIDMsIDQsIDVdCmxlbmd0aCA9IGxlbihkaW5ncykKc3VtKDEvZGluZ3Nba10sIGssIDAsIGxlbmd0aCAtMSAp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

<module> File "/tmp/tmpDDv20Z/___code___.py", line 5, in <module> exec compile(u'sum(_sage_const_1 /dings[k], k, _sage_const_0 , length -_sage_const_1 ) File "", line 1, in <module>

<module> File "expression.pyx", line 4163, in sage.symbolic.expression.Expression.__index__ (sage/symbolic/expression.cpp:20198) File "expression.pyx", line 745, in sage.symbolic.expression.Expression._integer_ (sage/symbolic/expression.cpp:5152) TypeError: unable to convert x (=k) to an integer

integer

So I tried writing it with dings[int(k)], didn't work either.

Why? Thanks!