Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Fix IndexError Based on Len()

Can anyone help fix an error happening on the line "for i in range(1,len(sums)-1):"? I'm relevantly new to sage and more use to python but the few differences sage has I think have been taken into account but I can't figure out what is causing this IndexError..

def Ramanujan(t):
    cubes = [x**3 for x in range(1,t/10)];
    crev = [] # Calculating Cube Roots;
    for x,x3 in enumerate(cubes):
        crev[x3] = x + 1;
        sums = sorted(x + y for x in cubes for y in cubes if y < x) # Organizing Data
        for i in range(1,len(sums)-1):
            if sums[i-1] != sums[i] and sums[i] == sums[i+1]: # Finding solutions
                if sums[i]<=t: # Limiting how many solutions printed.
                    print "%10d"%(sums[i]) # Printing desired outputs
                else:
                    break # Ending the function.

Ramanujan(10000)

Error:

Traceback (most recent call last):            for i in range(1,len(sums)-1):

File "", line 1, in <module>

File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 16, in <module> exec compile(u'Ramanujan(_sage_const_10000 ) File "", line 1, in <module>

File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 7, in Ramanujan crev[x3] = x + _sage_const_1 ; IndexError: list assignment index out of range

Does anyone have an idea of how to fix the IndexError I am running across?

Fix IndexError Based on Len()

Can anyone help fix an error happening on the line "for i in range(1,len(sums)-1):"? I'm relevantly new to sage and more use to python but the few differences sage has I think have been taken into account but I can't figure out what is causing this IndexError..

def Ramanujan(t):
    cubes = [x**3 for x in range(1,t/10)];
    crev = [] # Calculating Cube Roots;
    for x,x3 in enumerate(cubes):
        crev[x3] = x + 1;
        sums = sorted(x + y for x in cubes for y in cubes if y < x) # Organizing Data
        for i in range(1,len(sums)-1):
            if sums[i-1] != sums[i] and sums[i] == sums[i+1]: # Finding solutions
                if sums[i]<=t: # Limiting how many solutions printed.
                    print "%10d"%(sums[i]) # Printing desired outputs
                else:
                    break # Ending the function.

Ramanujan(10000)

Error:

Traceback (most recent call last):            for i in range(1,len(sums)-1):

File "", line 1, in <module>

File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 16, in <module>
 exec compile(u'Ramanujan(_sage_const_10000 )
 File "", line 1, in <module>

<module> File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 7, in Ramanujan crev[x3] = x + _sage_const_1 ; IndexError: list assignment index out of range

range

Does anyone have an idea of how to fix the IndexError I am running across?

Fix IndexError Based on Len()

Can anyone help fix an error happening on the line "for i in range(1,len(sums)-1):"? I'm relevantly new to sage and more use to python but the few differences sage has I think have been taken into account but I can't figure out what is causing this IndexError..

def Ramanujan(t):
    cubes = [x**3 for x in range(1,t/10)];
    crev = [] # Calculating Cube Roots;
    for x,x3 in enumerate(cubes):
        crev[x3] = x + 1;
        sums = sorted(x + y for x in cubes for y in cubes if y < x) # Organizing Data
        for i in range(1,len(sums)-1):
            if sums[i-1] != sums[i] and sums[i] == sums[i+1]: # Finding solutions
                if sums[i]<=t: # Limiting how many solutions printed.
                    print "%10d"%(sums[i]) # Printing desired outputs
                else:
                    break # Ending the function.

Ramanujan(10000)

Error:

Traceback (most recent call last):            for i in range(1,len(sums)-1):

File "", line 1, in <module>

<module>

File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 16, in <module>
exec compile(u'Ramanujan(_sage_const_10000 )
File "", line 1, in <module>

File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 7, in     Ramanujan
crev[x3] = x + _sage_const_1 ;
IndexError: list assignment index out of range

Does anyone have an idea of how to fix the IndexError I am running across?

Can't Figure out how to Fix IndexError Based on Len()

Can anyone help fix an error happening on the line "for i in range(1,len(sums)-1):"? I'm relevantly new to sage and more use to python but the few differences sage has I think have been taken into account but I can't figure out what is causing this IndexError..

def Ramanujan(t):
    cubes = [x**3 for x in range(1,t/10)];
    crev = [] # Calculating Cube Roots;
    for x,x3 in enumerate(cubes):
        crev[x3] = x + 1;
        sums = sorted(x + y for x in cubes for y in cubes if y < x) # Organizing Data
        for i in range(1,len(sums)-1):
            if sums[i-1] != sums[i] and sums[i] == sums[i+1]: # Finding solutions
                if sums[i]<=t: # Limiting how many solutions printed.
                    print "%10d"%(sums[i]) # Printing desired outputs
                else:
                    break # Ending the function.

Ramanujan(10000)

Error:

Traceback (most recent call last):            for i in range(1,len(sums)-1):
  File "", line 1, in <module>

File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 16, in <module>
exec compile(u'Ramanujan(_sage_const_10000 )
File "", line 1, in <module>

File "/private/var/folders/96/g5hyl4ps29dglpy8fnwww6x80000gn/T/tmpWiTKG1/___code___.py", line 7, in     Ramanujan
crev[x3] = x + _sage_const_1 ;
IndexError: list assignment index out of range

Does anyone have an idea of how to fix the IndexError I am running across?