python - I can't find a simple filter for my pyth triples filter -
i want filter down primitive triples ([3,4,5], [7,24,25], etc.) nothing non-primitive [6,8,10] , can't seem figure out, in code took out attempts @ filter, , displays primitive , non-primitive triples.
import tkinter import sys fractions import gcd def func(event): x = int(e1.get()) # max number result = [] in range(1, x): # loops each value in range of x b in range(a, x): c in range(b, x): if a**2 + b**2 == c**2 , gcd(a, b) == 1: # if primitive pyth triple, append result result += ['[',a,',',b,',',c,']'] # add group of triples list l = tkinter.message(root, text=result).grid(ipadx=5, ipady=5, sticky='w''e') # display each group of triples root l0 = tkinter.label(root, text="non-primitive , primitive triples").grid(ipadx=5, ipady=5, sticky='w''e') root.bind('<return>', close) # hit enter exit, temp debugging, reassign button later def close(event): # close program, define parameter event allow binding tkinter.sys.exit(0) sys.exit(0) root = tkinter.tk() # establish main gui root.title('generator') e1 = tkinter.entry(root) assert isinstance(e1, object) # method i've found allow entry().grid() e1.grid(ipadx=5, ipady=5, sticky='w''e') root.bind('<return>', func) # bind enter, cleaner , quicker button root.mainloop()
import gcd (from fractions import gcd
) , add test line check if triple pythagorean this:
if a**2 + b**2 == c**2 , gcd(a, b) == 1:
that should produce primitive triples.
Comments
Post a Comment