Python Forum
How do I stop this fast factorization program from printing beyond the 3rd output?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I stop this fast factorization program from printing beyond the 3rd output?
#7
(Dec-07-2019, 06:47 PM)Gribouillis Wrote: In the first code, I suppose it's yours, you wrote f = .... You only need to do the same.

Thanks a million I figured it out with your help of course :) Dance

import itertools as itt
while True: 
    def gen_factors(x):
        for i in range(1, x + 1):
            if x % i == 0:
                yield i
     
    def print_factors(x, maxcnt=None):
        g = gen_factors(x)
        if maxcnt is not None:
            g = itt.islice(g, 0, maxcnt)
        for p in g:
            print(p)
    p = int(input('Enter a prime number and if the output is 1 and itself its prime: '))
    p = (2**p-1)
    k = ((p**2*2))
    f = (k//2//p)
    if __name__ == '__main__':
        print_factors(p, 3)

Reply


Messages In This Thread
RE: How do I stop this fast factorization program from printing beyond the 3rd output? - by Pleiades - Dec-07-2019, 08:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how come i can't stop program Shi_Shi_Shi_Shi 4 690 Nov-16-2023, 06:20 PM
Last Post: deanhystad
  How to programmatically stop a program in Jupyter Notebook? Mark17 11 38,039 Feb-12-2023, 01:41 PM
Last Post: jp21in
  waiting for barcode scanner output, while main program continues to run lightframe109 3 4,737 Sep-03-2020, 02:19 PM
Last Post: DeaD_EyE
  How to get program output from subprocess.Popen? glestwid 1 2,411 Aug-19-2020, 05:44 AM
Last Post: buran
  how can we record a video file from our program output (moving object) Zhaleh 0 1,852 Aug-03-2020, 02:47 PM
Last Post: Zhaleh
  Printing output without print usage susmith552 1 1,716 Feb-07-2020, 07:52 PM
Last Post: Clunk_Head
  How to Stop Sentinel Value from Entering Final Output ZQ12 3 3,316 Nov-11-2019, 07:25 AM
Last Post: perfringo
  Juicy highly composite number needs factorization kevolegend 15 5,853 Jun-03-2019, 01:11 PM
Last Post: heiner55
  class program no output under python 3.5.1 jolinchewjb 1 2,410 Jan-22-2019, 10:53 AM
Last Post: Larz60+
  ciscolib cdp output list printing support anna 3 3,397 Jul-25-2018, 12:18 PM
Last Post: buran

Forum Jump:

User Panel Messages

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