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?
#1
I have a problem with this python37 code during printing and I would like it not to print out beyond the 3rd print statement of the loop. The program is super fast for a factorization program if I can only have a number (print_factors(f)) to print just below the 4th output when needed.

For example 3 prints like this:

The factors of 3 are: 1, 3

If I input 2047 it prints like this:

The factors of 2047 are: 1, 23, 89, 2047

However I would just like it to show up to 89. Here is the code:

You can get some points if you answer this at stackexchange:

https://stackoverflow.com/questions/5922...-3rd-outpu


import math
while True:
    def print_factors(x):
       print("The factors of",x,"are:")
       for i in range(1,x+1):
           if x % i == 0:
               print(i)
               


    p = int(input('Enter a prime number and if the output is 1 and itself its prime: '))
    
   
    k = ((p**2*2))
    l = (((pow(2, k + 1, 2 * k) - 1) % (2 * k)))
    f = (k//2//p)
    print_factors(f)
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  how come i can't stop program Shi_Shi_Shi_Shi 4 631 Nov-16-2023, 06:20 PM
Last Post: deanhystad
  How to programmatically stop a program in Jupyter Notebook? Mark17 11 37,473 Feb-12-2023, 01:41 PM
Last Post: jp21in
  waiting for barcode scanner output, while main program continues to run lightframe109 3 4,704 Sep-03-2020, 02:19 PM
Last Post: DeaD_EyE
  How to get program output from subprocess.Popen? glestwid 1 2,390 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,834 Aug-03-2020, 02:47 PM
Last Post: Zhaleh
  Printing output without print usage susmith552 1 1,682 Feb-07-2020, 07:52 PM
Last Post: Clunk_Head
  How to Stop Sentinel Value from Entering Final Output ZQ12 3 3,266 Nov-11-2019, 07:25 AM
Last Post: perfringo
  Juicy highly composite number needs factorization kevolegend 15 5,669 Jun-03-2019, 01:11 PM
Last Post: heiner55
  class program no output under python 3.5.1 jolinchewjb 1 2,388 Jan-22-2019, 10:53 AM
Last Post: Larz60+
  ciscolib cdp output list printing support anna 3 3,355 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