简体   繁体   English

TypeError 'Module' 对象不可调用(SymPy)

[英]TypeError 'Module' object is not callable (SymPy)

As the Topic says, module is not callable and I don't really understand why.正如主题所说,模块不可调用,我真的不明白为什么。 Its (probably) not the same problem from the similar post, at least I don't know what should I import.它(可能)与类似帖子中的问题不同,至少我不知道我应该导入什么。 I am using SymPy.我正在使用 SymPy。

And this is a full error text:这是一个完整的错误文本:

Traceback (most recent call last):
      File "C:\Users\Marek\Desktop\Bartłomiej\SymPy\PrimeTest.py", line 16, in <module>
        if isinstance(evalf((n/p).subs(x, 1)), int):
    TypeError: 'module' object is not callable

Full code:完整代码:

from sympy import *
import math 
import sys
import mpmath
sys.modules['sympy.mpmath'] = mpmath

x, y = symbols(' x y ')

#p = sympfy(input(Check this: ))
p = 100

n = expand(((x-1)**p - (x**p - 1)))

print(n) 

if isinstance(evalf((n/p).subs(x, 1)), int):
    print("This number is a prime!")
else:
    print("It is not a prime")

I am trying to make a test for a prime number.我正在尝试对质数进行测试。 (x-1)^p - (x^p - 1), if this is dividable by p and p != 1 then its a prime. (x-1)^p - (x^p - 1),如果它可以被 p 整除并且 p != 1 那么它就是一个素数。 My code is not quality because I am changing x to 1 , but I wanna check if it would work..我的代码质量不高,因为我将 x 更改为 1 ,但我想检查它是否有效..

I think you're using evalf() incorrectly.我认为您使用 evalf() 不正确。

From what I've seen, it should be ((n/p).subs(x, 1)).evalf()从我所看到的,它应该是((n/p).subs(x, 1)).evalf()

https://docs.sympy.org/latest/modules/evalf.html https://docs.sympy.org/latest/modules/evalf.html

It might be something else, but give it a try.它可能是别的东西,但试一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM