Missing 1 required positional argument

asked 2020-01-17 15:07:01 +0200

updated 2020-01-18 05:57:38 +0200

What's wrong with my code? It doesn't work inside Sage Math Cell.

gp.eval("xmat(r,n) = [2*x, -1; 1, 0]*Mod(1,x^r-1)*Mod(1,n);")
gp.eval("smallestr(n)={if(n==1 || n%2==0, return(0));forprime(r = 3, oo,my(u=n%r);if (u==0 && r < n, return(0));if (u!=0 
&& u!=1 && u!=r-1, return(r)));}")
gp.eval("myisprime(n)={my(r = smallestr(n));if (r == 0, return(n == 2));my(xp = xmat(r,n)^n*[x,1]~);xp[2] == 
Mod(x*Mod(1,n),x^r-1)^n;}")
def Check(n):
if gp.function_call("myisprime",[n]).sage()==true:
    return ("Prime!")
else:
    return ("Composite!")
@interact
def _(n=2017,action=selector(['Check'],buttons=True,label='')):
     action = eval(action) 
     print (action())

I am getting the following message: TypeError: Check() missing 1 required positional argument: 'n'

EDIT

You can run this code here.

edit retag flag offensive close merge delete

Comments

1

As it's written, the indentation is bad: the four lines after def Check(n): should be indented four more spaces.

John Palmieri gravatar imageJohn Palmieri ( 2020-01-17 18:52:10 +0200 )edit

@JohnPalmieri You are right, but that's not issue. Please see edit.

Pedja gravatar imagePedja ( 2020-01-18 05:59:21 +0200 )edit
1

@JohnPalmieri I have found a problem. The last line should read: print(action(n)) .

Pedja gravatar imagePedja ( 2020-01-18 06:38:31 +0200 )edit

with the two corrections, why there is no slider present on sageCell but there is one on Jupyter notebook ?

ortollj gravatar imageortollj ( 2020-01-18 16:25:55 +0200 )edit