Python Forum
Avoid multiple repeat in indent
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Avoid multiple repeat in indent
#1
Hello,

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
Reply


Messages In This Thread
Avoid multiple repeat in indent - by Frankduc - Jan-17-2022, 04:35 PM
RE: Avoid multiple repeat in indent - by BashBedlam - Jan-17-2022, 04:39 PM
RE: Avoid multiple repeat in indent - by Frankduc - Jan-17-2022, 04:46 PM
RE: Avoid multiple repeat in indent - by BashBedlam - Jan-17-2022, 07:37 PM
RE: Avoid multiple repeat in indent - by Frankduc - Jan-18-2022, 02:06 PM
RE: Avoid multiple repeat in indent - by deanhystad - Jan-18-2022, 12:40 PM
RE: Avoid multiple repeat in indent - by Frankduc - Jan-18-2022, 02:56 PM
RE: Avoid multiple repeat in indent - by deanhystad - Jan-18-2022, 03:59 PM
RE: Avoid multiple repeat in indent - by Frankduc - Jan-18-2022, 05:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  getting unexpected indent errors trying to move cells up jensengt 4 1,003 Jun-28-2023, 12:05 PM
Last Post: deanhystad
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 1,724 Jun-09-2023, 08:42 PM
Last Post: ctrldan
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,542 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Repeat request by else stsxbel 2 1,278 Jul-30-2022, 03:34 PM
Last Post: stsxbel
  IndentationError: unexpected indent dee 3 2,535 May-02-2022, 02:15 AM
Last Post: dee
  get out of while loop and stop repeat Frankduc 11 3,270 Apr-26-2022, 10:09 PM
Last Post: deanhystad
  How to discard list repeat values akanowhere 7 3,875 Dec-28-2020, 09:14 PM
Last Post: akanowhere
  I want to check if the input is str or is int & if it's str repeat the loop HLD202 4 2,924 Nov-23-2020, 11:01 PM
Last Post: perfringo
  IndentationError: unexpected indent jk91 1 2,467 Feb-27-2020, 08:56 PM
Last Post: buran
  is there a way: repeat key word args Skaperen 2 2,347 Feb-03-2020, 06:03 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020