Python Forum
Creating a program to look for the largest prime number of a number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a program to look for the largest prime number of a number
#1
So I'm creating a code that will take on number look for all the factors of that number and then tell me what factors are prime and which ones are not
num = (random number) <==This a preinputed number.

def print_factors(x):
    print("factors of", x,"are:")
    for i in range(1,x + 1):
        if x % i ==0:
            print(i)
print_factors(num)
I think the way to do it would be to have the program put all the factors into a list and then run a prime number program through it but I don't know how to do that and would love the help/criticism or whatever you have.
Thanks for the help, Wikki14
Reply
#2
Please use python tags when posting code, see the BBCode link in my signature below for instructions. I did it for you this time.

I would both sets of factors at the same time. Start with two and go up. The first factor you find is guaranteed to be prime. Put that in the prime factors list. Then every factor you find is either evenly divisible by one of the prime factors, or another prime factor.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
it would seem to me that a generator that yields prime numbers in increasing sequence could be useful here.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(Sep-02-2018, 11:53 PM)Wikki14 Wrote: put all the factors into a list and then run a prime number program
The smallest factor (after 1) is necessarily a prime number. If you find it, you can divide x by this factor.
Reply
#5
(Sep-07-2018, 04:57 AM)Gribouillis Wrote:
(Sep-02-2018, 11:53 PM)Wikki14 Wrote: put all the factors into a list and then run a prime number program
The smallest factor (after 1) is necessarily a prime number. If you find it, you can divide x by this factor.
then after you divide x by this (smallest) factor, apply all this to the quotient you get. its smallest factor is also prime ...
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Control of the number of daemon error messages to the file MarPan 3 87 Mar-25-2026, 11:00 AM
Last Post: DeaD_EyE
  Exponential Number Conversion Tuurbo46 4 765 Jan-09-2026, 08:47 PM
Last Post: DeaD_EyE
  [split] print two different sequence number Reema 1 686 Nov-10-2025, 05:37 AM
Last Post: Gribouillis
  Creating a Mindmap program J_Miller 4 11,019 Sep-23-2025, 12:00 PM
Last Post: Pedroski55
  Send SMS from my phone number aster 4 4,789 May-11-2025, 05:48 PM
Last Post: TheTechNexus
Question [redistribution] Reduce number + size of dependencies? Winfried 2 1,344 Jan-31-2025, 10:17 PM
Last Post: snippsat
  Syntax for Doubling a number ksp_802 3 1,466 Jan-12-2025, 07:04 PM
Last Post: ksp_802
  Printing the code line number arbiel 6 2,549 Jun-30-2024, 08:01 AM
Last Post: arbiel
  Finding the price based on industry and number of transactions chandramouliarun 1 2,213 Jun-04-2024, 06:57 PM
Last Post: marythodge4
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 1,635 May-13-2024, 10:59 PM
Last Post: ebn852_pan

Forum Jump:

User Panel Messages

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