Primality test stops responding

时间:2016-04-04 18:38:18

标签: python tkinter

My tkinter program stops responding for large primes in my primality tests. I would rather it take a longer time, than stop working all together. How do I accomplish this?

Thanks.

class PageSeven(tk.Frame):

def __init__(self, parent, controller):

    tk.Frame.__init__(self, parent)

    xf = ttk.Frame(self, relief = "groove")

    def show_answer():
        ans = int(entry.get())
        label2.config(text = str(C.ll(ans)))


    label1 = ttk.Label(xf, text="Please enter the value for n. ")
    label1.grid(row=0, column = 0, padx = 2, pady = 2)

    entry = ttk.Entry(xf)
    entry.grid(row=0, column=1, padx = 2, pady = 2)

    button = ttk.Button(xf, text = "Go", command = show_answer)
    button.grid(row = 1, column = 0, padx = 2, pady = 2)

    label2 = ttk.Label(xf, text = "The answer will appear here. ")
    label2.grid(row=1, column = 1, padx = 2, pady = 2)

    xf.grid(row=0, column = 0)

And this is the function ll:

def seq(n):
    M = 2**n - 1 
    num = [4]
    for i in range(2,n):
        value = num[-1]
        val = value**2 - 2
        v = val % M
        num.append(v)
    return num

def ll(n):
    if isprime(n) == 0:
        return False
    else:
        if seq(n)[-1] == 0:
            return True
        else:
            return False

as requested.

Thank you.

0 个答案:

没有答案