来自Mathematics Stack Exchange的

This question was migrated,因为可以在Stack Overflow上进行回答。
                            Migrated 3年前。
                        
                    
                
                            
                    
我一生中从未使用过SageMath,而是依靠互联网上的速成班了解如何从SageMath中获得想要的东西(在有限域上绘制椭圆曲线)。

我正在使用this code,粘贴在下面:

@interact
def f(label='37a', p=tuple(prime_range(1000))):
 try: E = EllipticCurve(label)
 except:
 print "invalid label %s"%label; return
 try:
show(graphics_array([plot(E,thickness=3),plot(E.change_ring(GF(p)))]),frame=True)
 except Exception, msg:
 print msg


似乎缺少一个括号,但是我没有经验知道应该去哪里。我收到的错误消息是:

Error in lines 1-6
Traceback (most recent call last):
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "<string>", line 4
    except:
          ^
IndentationError: unindent does not match any outer indentation level

最佳答案

您所给出的错误似乎表明except:之后的行缩进不超过except:。 Python非常关心缩进级别。

您可以尝试以下方法。

@interact
def f(label='37a', p=tuple(prime_range(1000))):
    try:
        E = EllipticCurve(label)
    except:
        print "invalid label %s"%label; return
    try:
        show(graphics_array([plot(E,thickness=3), plot(E.change_ring(GF(p)))]), frame=True)
    except Exception, msg:
        print msg


除了:您应在代码前使用四个空格,以使其显示为代码块。有关更多信息,请参见How do I format My Code Blocks?

关于sage - 在SageMath中绘制椭圆曲线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36186615/

10-13 07:22