The numbers in your sample tree are correct, but the 000 separator looks sometimes like a decimal point , a bit confusing, but it is to show concatenation.
I'm not sure how to proceed in this homework section, because my approach is quite different.
If the purpose is to use recursion, i see no need for it, but a python "evangelist" might. :-)
I also see no need for the dictionary , nor the list of primes
e.g. to find the divisors of a number, i use this:
We also assume that the seed number is semi-prime, although if it is not, the iterations will stop soon enough.
the new_numbers() function generates 'xy' and 'yx', that are added to a list.
You then call divisors() for the listed results.
Paul
I'm not sure how to proceed in this homework section, because my approach is quite different.
If the purpose is to use recursion, i see no need for it, but a python "evangelist" might. :-)
I also see no need for the dictionary , nor the list of primes
e.g. to find the divisors of a number, i use this:
def divisors(x): div = [] for i in range(2,int(x/2)+1): if x % i == 0: div.append(i) if len(div) == 2: print(f'Divisors of {x}', div) new_numbers(div) else: print(f'{x} is Not Semi Prime')I assume by your definition that a semiprime can only have 2 divisors, both prime.
We also assume that the seed number is semi-prime, although if it is not, the iterations will stop soon enough.
the new_numbers() function generates 'xy' and 'yx', that are added to a list.
You then call divisors() for the listed results.
Paul
Output:Start: 15
Divisors of 15 [3, 5]
New numbers: 53 35
Divisors of 35 [5, 7]
New numbers: 75 57
53 is Not Semi Prime
Divisors of 57 [3, 19]
New numbers: 193 319
75 is Not Semi Prime
Divisors of 319 [11, 29]
New numbers: 2911 1129
193 is Not Semi Prime
1129 is Not Semi Prime
Divisors of 2911 [41, 71]
New numbers: 7141 4171
Divisors of 4171 [43, 97]
New numbers: 9743 4397
Divisors of 7141 [37, 193]
New numbers: 19337 37193
4397 is Not Semi Prime
9743 is Not Semi Prime
Divisors of 37193 [13, 2861]
New numbers: 286113 132861
Divisors of 19337 [61, 317]
New numbers: 31761 61317
132861 is Not Semi Prime
286113 is Not Semi Prime
61317 is Not Semi Prime
31761 is Not Semi Prime
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.