Sep-01-2020, 08:17 PM
Sure. Ok, here's some code. I know it's not pretty and it still needs some fixing
but it seems to work good enuf for testing purposes. This creates a dictionary of
semi-primes and their factors.
Still working on that. (OBTW, while I am still learning Python, this
is not homework. I found this problem on another website, thought it
looked interesting and decided to try to figure out how to program it.)
but it seems to work good enuf for testing purposes. This creates a dictionary of
semi-primes and their factors.
sp_dict = {} primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] def semi(): for i in range(9, 101, 2): #for the real thing this range will be much larger divisors = [] for j in primes: if j > math.sqrt(i): continue else: div = i / j if div == int(div): divisors.append(j) divisors.append(div) if len(divisors) == 2: value = "(" + str(divisors[0]) + ", " + str(int(divisors[1])) + ")" sp_dict[i] = value print(sp_dict) a = semi()I haven't yet got the code to pull the info out of the dictionary.
Still working on that. (OBTW, while I am still learning Python, this
is not homework. I found this problem on another website, thought it
looked interesting and decided to try to figure out how to program it.)