Friday, July 1, 2022
HomeProgrammingPython Program to Discover Prime Elements of a Quantity

Python Program to Discover Prime Elements of a Quantity


If a quantity p is totally divisible by one other quantity q, then q is claimed to be an element of p. Right here q can be larger than 1 and fewer than or equal to p.

So, if a quantity p is totally divisible by one other quantity q and q is a primary quantity then q is claimed to be a primary issue of p.

Prime numbers are these numbers which might be solely divisible by 1 and themselves. On this article, we are going to see the code to seek out the prime components of a quantity.

For instance:

If we take 5, then prime components can be:

5 = 5

5 is the one prime issue of 5.

If we take 20, then prime components can be:

20 = 2 * 2 * 5

If we take 210, then prime components can be:

210 = 2 * 3 * 5 * 7

Now let’s see the code of this drawback. On this code, we can be creating two features. The primary operate will assist us to know if a quantity is prime or not. And the second operate will assist us to print the prime issue of a quantity.

Testcase 1: When the enter is 100.

Output:

Testcase 2: When the Enter is 270270.

Output:

Python Program to Find Prime Factors of a Number

Now we have used two features to create the entire program.

The primary operate will inform us if a quantity is prime or not. It takes an integer and returns a Boolean worth (True or false).

The second operate will assist to print the prime components of a quantity. It is going to take an integer as enter and print all of the prime components of that enter. It returns None as a result of all of the printing is finished throughout the operate solely.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments