Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can't find Cause of Traceback Error

I'm trying to convert this code that runs in Python 2.7 to Sage but can't even get a hint from Sage at what line the code is not accepted by Sage.

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.'''

The only thing that Sage will report back is Traceback Error for SyntaxError: invalid syntax but no line information.. Can anyone tell where specifically the syntax is invalid??

Can't find Cause of Traceback Error

I'm trying to convert this code that runs in Python 2.7 to Sage but can't even get a hint from Sage at what line the code is not accepted by Sage.

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
outputs '''
            else:
                break ''' Ending the function.'''

The only thing that Sage will report back is Traceback Error for SyntaxError: invalid syntax but no line information.. Can anyone tell where specifically the syntax is invalid??