Jan-17-2022, 04:35 PM
Hello,
I am trying to count the number of pairs but in the end i only want the variable count give the total.
I just want the total 2 pairs
Thank you
I am trying to count the number of pairs but in the end i only want the variable count give the total.
import itertools lim = int(input("Generate prime numbers up to : ")) listo = [] def prime_eratosthenes(lim): prime_list = [] for i in range(2, lim+1): if i not in prime_list: print (i, end = ' ') listo.append(i) for j in range(i*i, lim+1, i): prime_list.append(j) # print(j) return listo def printPairs(lim): primes = prime_eratosthenes(lim) for i in range(0, len(primes)): for j in range(i+1, len(primes)): if (primes[i]*primes[j])==lim: print(' ') print("Primes multiply that gives: ",lim) print(primes[i], primes[j]) printPairs(lim) print('') print('Primes sum that gives:', lim) som = 0 count = 0 for L in range(0, len(listo)+1): for subset in itertools.combinations(listo, L): som = sum(subset) if (som == lim): print(som, subset) count += 1 print("Number of pairs: ", count)
Output:Generate prime numbers up to : 10
2 3 5 7
Primes multiply that gives: 10
2 5
Primes sum that gives: 10
10 (3, 7)
Number of pairs: 1
10 (2, 3, 5)
Number of pairs: 2
>
Its only repeating number of pairs 1, 2 ...I just want the total 2 pairs
Thank you