简体   繁体   中英

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.

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. My code is not quality because I am changing x to 1 , but I wanna check if it would work..

I think you're using evalf() incorrectly.

From what I've seen, it should be ((n/p).subs(x, 1)).evalf()

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

It might be something else, but give it a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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