Python Forum
Avoid multiple repeat in indent
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Avoid multiple repeat in indent
#4
(Jan-17-2022, 04:46 PM)Frankduc Wrote: Also is it possible to initialize the variable count at the top so that the numbers count appear just after Primes sum that gives:?
Do you mean like this?
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)
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('')
print('Primes sum that gives:', lim)
print("Number of pairs: ", count)
Also, if you give it an 85 or 86 to chew on, you can see how long it takes. I think 100 is just overloading something.
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 927 Jun-28-2023, 12:05 PM
Last Post: deanhystad
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 1,593 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,441 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Repeat request by else stsxbel 2 1,232 Jul-30-2022, 03:34 PM
Last Post: stsxbel
  IndentationError: unexpected indent dee 3 2,417 May-02-2022, 02:15 AM
Last Post: dee
  get out of while loop and stop repeat Frankduc 11 3,137 Apr-26-2022, 10:09 PM
Last Post: deanhystad
  How to discard list repeat values akanowhere 7 3,787 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,859 Nov-23-2020, 11:01 PM
Last Post: perfringo
  IndentationError: unexpected indent jk91 1 2,419 Feb-27-2020, 08:56 PM
Last Post: buran
  is there a way: repeat key word args Skaperen 2 2,286 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